簡體   English   中英

Android ListView僅在滾動后顯示ListSelector

[英]Android ListView displays ListSelector only after scrolling

我向ListView添加了一個簡單的ListSelector 問題是,在ListView稍微滾動一下之后,才顯示ListSelector

如何使ListSelector在選擇時立即出現?

列表顯示

<ListView
    android:id="@+id/contentListView"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" 
    android:layout_above="@id/buttonEntwerten" 
    android:scrollingCache="false"
    android:cacheColorHint="#00000000"

    android:listSelector="@drawable/list_selector"
/>

@ drawable / list_selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:drawable="@drawable/list_selector__gradient_bg_hover" />
</selector>

您可以查看android如何對其進行配置,並進行相應的更改(文件名為“ list_selector_background.xml”):

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_window_focused="false" android:drawable="@color/transparent" />

    <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
    <item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_disabled" />
    <item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/list_selector_background_disabled" />
    <item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
    <item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
    <item android:state_focused="true"                                                             android:drawable="@drawable/list_selector_background_focus" />

</selector>

簡而言之,您只需要處理state_pressed state。 其余的都是要處理的好狀態。

您的代碼中的問題是它沒有狀態。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM