2013.03.19(4)———activity ListView点击效果实现总结
2013.03.19(4)———activity ListView点击效果实现总结
参考:http://www.cnblogs.com/loulijun/archive/2012/04/15/2450312.html
个人总结:
实现ListView的点击效果,有两种方式,一种是color,一种用图片。
1、color
这个最好写在android:listSelector里面
<ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/room_tab_user_lv_user" android:divider="#00000000" android:cacheColorHint="#00000000" android:listSelector="@drawable/listitem_background" />
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape> <corners android:radius="10dip" /> <stroke android:width="1dp" android:color="#aaaaaa" /> <gradient android:startColor="#ff8c00" android:endColor="#FFFFFF" /> </shape> </item> <item android:drawable="@android:color/transparent" /></selector>
<ListView android:layout_width="fill_parent" android:layout_height="300dip" android:id="@+id/room_tab_chat_lv_msg" android:divider="#00000000" android:cacheColorHint="#00000000" android:listSelector="#00000000" android:transcriptMode="normal" android:layout_weight="1" android:layout_margin="5dip" android:dividerHeight="2dip" />
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:paddingTop="5dip" android:paddingBottom="5dip" android:background="@drawable/setting_more_bg_click" > <ImageView android:layout_width="32dip" android:layout_height="32dip" android:id="@+id/room_tab_chat_item_iv_photo" android:scaleType="fitXY" /> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginLeft="5dip" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/room_tab_chat_item_tv_nickname" style="@style/mTxt" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/room_tab_chat_item_tv_msg" style="@style/mTxt" /> </LinearLayout></LinearLayout>
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/setting_more_bg_gray" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/setting_more_bg_gray" /> <!-- focused --> <item android:drawable="@drawable/setting_more_bg"></item></selecto