【问题标题】:Hanged listSelector in ListViewListView 中的挂起 listSelector
【发布时间】:2012-10-05 22:57:40
【问题描述】:

我正在用android:listSelector 实现ListView

<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 的顶部或底部。我将不胜感激。

【问题讨论】:

标签: android listview user-interface scroll scrollview


【解决方案1】:

主要问题是您使用的是纯色而不是 Drawables。布局框架有个缺点,就是设置纯色,就会出现hold的问题。

你使用的代码:

<item name="android:listSelector">@color/red</item>

应该用作:

    <item name="android:listSelector">@drawable/list_view_selector</item> 

上面写的drawable应该包含在selector标签中。

这是 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>

注意:您不能按原样使用纯色。您必须将每种色调的选择器设置为:

<?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>

我已经检查过了。工作完美!!

【讨论】:

  • 即使使用这个解决方案我也有这个问题......而且 ListView 数据也在选择器下滚动......
  • 即使有这个解决方案,我也有这个问题。我在选择器中有正常的状态项,它挂在列表中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-08
  • 1970-01-01
相关资源
最近更新 更多