【问题标题】:ListView background attribute causes all items to be highlighted when one is selectedListView 背景属性使所有项目在选中时突出显示
【发布时间】:2013-11-03 11:57:13
【问题描述】:

在我的 Android 应用程序中,当用户按下列表中的某个项目时,该项目正确地以蓝色突出显示,但列表中的所有其他项目也以灰色突出显示。当用户抬起手指时,高光就消失了。这会导致整个列表出现不受欢迎的“闪烁”效果。

如果我只从 ListView 中删除背景属性,闪烁效果就会消失。我正在寻找另一个修复方法,以便保留背景属性。

我使用的是 Android 17。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="8dip"
    android:paddingTop="0dip"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:textColor="@color/my_sky"
        android:background="@drawable/my_btn_white"
        android:id="@+id/my_list"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"/>

    <Button
        style="@style/MY.Flow.Button"
        android:id="@+id/my_add_choices"
        android:text="@string/my_favorites_add_choices"
        android:layout_marginTop="10dip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

【问题讨论】:

  • 我已经尝试了 android:listSelector="@android:color/transparent" 和 android:cacheColorHint="#00000000",正如其他线程中建议的那样,但无济于事。跨度>

标签: android listview android-listview


【解决方案1】:

我发现了问题。我的@drawable/my_btn_white 有以下行:

<item android:state_pressed="true" android:drawable="@drawable/my_btn_white_active"/>

当我删除这条线时,灰色高亮以及闪烁消失。

【讨论】:

    【解决方案2】:

    尝试添加到您的ListView

    android:cacheColorHint="@android:color/transparent"
    

    【讨论】:

    • 那没有效果。 :(
    • 已添加。这是在将 cacheColorHint 设置为 #00000000 时拍摄的。
    猜你喜欢
    • 2011-08-16
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    相关资源
    最近更新 更多