如何在点击时改变背景梯度,并在手指释放时获得原始梯度…我使用列表视图适配器创建的列表确实更改为梯度,但当我抬起手指时不会更改回原始梯度。
下面的xmlmain。xml
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#EDEDED"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
/>
listrongelector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->
<item android:state_focused="true"
android:drawable="@drawable/gradient_bg_hover"
/>
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/gradient_bg" />
<item android:state_pressed="true"
android:drawable="@drawable/gradient_bg_hover" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/gradient_bg_hover" />
</selector>
row_list.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txtListText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="15dp"
android:textSize="45sp"
/>
gradient_bg和gradient_bghover是gradient xml的..
我认为,你不能一次定义state_selected和state_pressed…
正常工作的东西应该是这样的:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/_bt_week_selected" />
<item android:state_focused="true" android:drawable="@drawable/_bt_week_selected"/>
<item android:state_pressed="true" android:drawable="@drawable/_bt_week_selected"/>
<item android:drawable="@drawable/_bt_week_normal"/>
</selector>
并将列表项(row_list)的背景设置为选择器…比如android:background="@drawable/selector"
……而不是用android:listSelector="@drawable/list_selector"