在ListView中吊死listSelector [英] Hanged listSelector in ListView
问题描述
我在执行的ListView
与安卓listSelector
<style name="ListView" parent="@android:style/Widget.ListView">
<item name="android:cacheColorHint">@color/transparent</item>
<item name="android:divider">@drawable/divider</item>
<item name="android:dividerHeight">1px</item>
<item name="android:listSelector">@color/red</item>
</style>
选择工作正常,但是当我开始滚动, listSelector
将随机挂到顶部或的ListView
的底部。我想AP preciate任何帮助。
Selecting works fine, but when I start scrolling, listSelector
will randomly hang to top or bottom of ListView
. I would appreciate any help.
推荐答案
主要的问题是,你使用的是纯色,而不是使用可绘制。它是在布局框架的缺点是,如果你设置纯色,然后按住的问题出现。
The main problem is that you are using a solid color instead of using Drawables. It is a drawback in the layout framework that if you set the solid colors, then the problem of hold occurs.
您正在使用的code为:
The code which you are using as :
<item name="android:listSelector">@color/red</item>
应作为
<item name="android:listSelector">@drawable/list_view_selector</item>
上面写绘制应包含在选择标签。
The above written drawable should be enclosed in the selector tag.
下面是code为list_view_selector
Here is the code for the list_view_selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_enabled="true"
android:state_pressed="true" android:drawable="@drawable/background_selected" />
<item android:state_enabled="true"
android:state_focused="true" android:drawable="@drawable/background_selected" />
<item android:state_enabled="true"
android:state_selected="true" android:drawable="@drawable/background_selected" />
</selector>
请注意:不能使用纯色,因为它是。你必须做出选择的每个色调为:
Note : You cannot use the solid color as it is. You have to make the selectors for the each color tone as :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:centerColor="#ff0000"
android:endColor="#ff0000"
android:startColor="#ff0000" />
</shape>
我已经在我结束检查这一点。工作完美!
I have checked this at my end. Working Perfect!!
这篇关于在ListView中吊死listSelector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!