http://www.cnblogs.com/allin/archive/2010/05/11/1732200.htmlhtml
二、Android中ListView的性能問題java
http://android.tgbus.com/Android/tutorial/201105/354459.shtmlandroid
三、設置背景色爲透明,防止滑動時,背景變黑ide
android:cacheColorHint="#00000000"性能
四、設置ListView控件條目被按下時背景顏色在文字背後,設置成True時背景色會覆蓋文字字體
android:drawSelectorOnTop="false" 優化
五、android:divider屬性:本屬性設置listView中的選項分隔符,可設置圖片,顏色等。spa
android:divider="#00000000" 設置爲無色,這樣顯示時,就沒有分隔線了。code
六、android:minHeight="?android:attr/listPreferredItemHeight" 設置最小高度由item決定orm
七、Listview更新:
在BaseAdapter的getView()方法中根據條件改變View的字體顏色、其中的圖片等,是不能當即在UI上顯示的,必須調用notifyDataSetChanged()方法,實現更新。
ListView不能局部更新(如今爲止我沒找到實現局部更新的方法,若有同窗有方法實現局部更新,盼賜教。),更新實現以下:
BaseAdapter adapter = new BaseAdapter();
adapter.notifyDataSetChanged();
八、更改ListView中選中框的TextView的字體顏色:
要改變TextView的顏色,需調用TextView的setTextColor()方法設置,在使用中發現,在BaseAdapter中的getView()中使用「name.setTextColor(R.color.background);」方式字體會是黑色,可用」name.setTextColor(Color.rgb(0, 234, 255));「方式改變字體顏色,「Color.rgb(0, 234, 255)」爲要設置的顏色的RGB值;最後在OnItemSelectedListener的onItemSelected()方法中調用」adapter.notifyDataSetChanged();「方法便可。
雖然這種方式能夠改變字體顏色,但不知道爲何?盼有知道的同窗解惑。
九、可擴展的ListView:ExpandableListView
ExpandableListView爲ListView子類,
十、代碼:
banner中的ListView定義
<ListView android:id="@+id/bannerList" android:layout_width="fill_parent" android:layout_height="fill_parent" android:listSelector="@drawable/banneritemfocus" android:cacheColorHint="#00000000" android:drawSelectorOnTop="false" android:divider="#00000000" android:minHeight="?android:attr/listPreferredItemHeight" android:focusable="true" />
ListItem定義
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:paddingLeft="10dip" android:paddingRight="8dip" android:paddingTop="1dip" android:paddingBottom="1dip" > <ImageView android:id="@+id/bannerPlay" android:layout_width="wrap_content" android:layout_height="fill_parent" android:src="@drawable/banner_play" /> <TextView android:id="@+id/bannertext" android:layout_width="wrap_content" android:layout_height="fill_parent" android:singleLine="true" android:textSize="14dip" android:gravity="center_vertical" android:textColor="@color/white" android:paddingTop="1dip" android:paddingBottom="1dip" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right" > <ImageView android:id="@+id/bannerok" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="right" android:visibility="invisible" android:src="@drawable/banner_ok" /> </LinearLayout> </LinearLayout>
java代碼:
private void showBannerListView() {
if(bannerPop == null) {
View v = getLayoutInflater().inflate(R.layout.banner, null);//加載包含ListView的定義
bannerPop = new PopupWindow(v);//新建PopupWiondow對象
bannerPop.setFocusable(true);//可得到焦點
bannerPop.setOutsideTouchable(true);//可點擊PopupWindow區域外事PopupWindow消失,會調用popupWIndow的dismiss()方法
bannerPop.setBackgroundDrawable(new BitmapDrawable());//使PopuPWIndow響應退出按鍵
bannerList = (ListView)v.findViewById(R.id.bannerList);
bannerAdapter = new BaseAdapter() {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView bannerPlay = null;
TextView name = null;
if(convertView == null) {//優化ListView性能
convertView = getLayoutInflater().inflate(R.layout.banner_item, null);
bannerPlay = (ImageView)convertView.findViewById(R.id.bannerPlay);
name = (TextView)convertView.findViewById(R.id.bannertext);
convertView.setTag(R.id.bannerPlay, bannerPlay);
convertView.setTag(R.id.bannertext, name);
}else {
bannerPlay = (ImageView)convertView.getTag(R.id.bannerPlay);
name = (TextView)convertView.getTag(R.id.bannertext);
}
bannerPlay.setVisibility(View.GONE);//設置不可見
name.setText(bannerData.get(position));//設置文字內容
int select = bannerList.getSelectedItemPosition();
if(position == curBannerIndex) {
bannerPlay.setVisibility(View.VISIBLE);
name.setTextColor(Color.rgb(0, 234, 255));//設置字體顏色 }else {
name.setTextColor(Color.rgb(255, 255, 255));
}
return convertView;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public int getCount() {
return bannerData.size();
}
};
bannerList.setAdapter(bannerAdapter);
bannerList.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Log.i(TAG, "00000in onItemSelected:position="+position+" id="+id+" view="+view+" parent="+parent);
canceBannerDelayHide();
hideBannerDelay();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Log.i(TAG, "11111111in onNothingSelected: parent="+parent);
}
});
bannerList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
canceBannerDelayHide();
String name = bannerData.get(position);
int index = name.indexOf(tvgap);//-1 爲電影
if(index == -1) {//電影,
childPositionIndex = 0;
}else {//電視劇,得到電視劇集數的childPositionIndex索引
String aa = name.substring(index + tvgap.length());
childPositionIndex = Integer.parseInt(aa) - 1;
name = name.substring(0, index);
}
String item[] = null;
for (int i = 0; i < favoriteData.size(); i++) {
item = favoriteData.get(i);
if(item[0].startsWith(name)){//可直接比較名稱,得到groupPositionIndex 索引
groupPositionIndex = i;
break;
}
}
hideBanner();
changeMove();
}
});
bannerList.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
canceBannerDelayHide();
}else if(event.getAction() == MotionEvent.ACTION_UP) {
hideBannerDelay();
}
return false;
}
});
}else {
bannerAdapter.notifyDataSetChanged();
}
bannerList.setSelection(curBannerIndex);
bannerPop.showAtLocation(vv, Gravity.TOP, controlx, controly);
bannerPop.update(controlx, controly, controlWidth, controlHeight);
hideBannerDelay();
}