选择在滚动中的Android ListView控件列表项移动颜色 [英] Selected list item color moves on scrolling the listView in Android
问题描述
在我的Android应用我使用列表视图。在code为列表视图如下:
In my Android application I am using listview. The code for list view is as follows
<ListView
android:id="@+id/inputselect_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:footerDividersEnabled="true"
android:headerDividersEnabled="true"
android:listSelector="@drawable/list_selector"
android:splitMotionEvents="true" >
</ListView>
当用户从列表视图则列表项发生改变背景颜色中选择一个项目,根据该行
When user selected one item from the listview then background color of list item changes according to this line
android:listSelector="@drawable/list_selector"
编辑:list_selector.xml
list_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_selected="true"
android:drawable="@android:color/transparent" />
<item android:state_selected="true"
android:drawable="@android:color/transparent" />
<item android:state_pressed="true" android:state_selected="false"
android:drawable="@android:color/transparent" />
<item android:state_selected="false"
android:drawable="@color/blue_train" />
</selector>
list_selector.xml是绘制文件夹指定颜色。
现在的问题是,当我选择列表视图一个项目,并滚动列表,然后选择项目的背景颜色也向下移动/向上按滚动。
使所选项目的背景颜色仍然是它在滚动请提供给我的解决方案。
list_selector.xml is in drawable folder to specify color. Now the problem is that when I select one item from listview and scrolls the list then selected item background color also move downward/upward according to scrolling. Please provide me solution so that selected item background color remains as it is on scrolling.
编辑:这里选择单一色item.Blue滚动列表视图的截图保留,因为它是
Here the screenshot of scrolling listview by selecting single item.Blue color remains as it is
请咨询。
推荐答案
似乎未清除的状态在选择导致此。使用一个像
seems uncleared states in selector causing this . use one like
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selected -->
<item
android:state_focused="true"
android:state_selected="false"
android:drawable="@drawable/focused"/>
<!-- Pressed -->
<item
android:state_selected="true"
android:state_focused="false"
android:drawable="@drawable/pressed" />
<!-- default -->
<item android:drawable="@drawable/default" />
</selector>
这篇关于选择在滚动中的Android ListView控件列表项移动颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!