我有一个使用自定义数组适配器的列表视图设置列表看起来很好我使用了渐变和每个项目的背景,它也出现了,但代码还指出在点击时更改渐变,下面没有发生是我的 xml
主要的.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:dividerHeight="0.1dp"
android:listSelector="@drawable/list_selector"
/>
row_list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/txtListText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="20dp"
android:textSize="35sp"
android:textColor="#545454"
android:background="@drawable/ogbg"
/>
</LinearLayout>
list_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/ogbg" />
<item android:state_pressed="true"
android:drawable="@drawable/ogpress" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/ogpress" />
</selector>
ogbg.xml// 普通背景渐变
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFAFAFA"
android:centerColor="#FFFFFFFF"
android:endColor="#FFFFFFFF"
android:angle="90"/>
</shape>
ogpress.xml//在点击时更改的渐变
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FF05c1ff"
android:endColor="#7F05c1ff"
android:angle="90"/>
</shape>