ListView 中挂起的 listSelector [英] Hanged listSelector in ListView

查看:26
本文介绍了ListView 中挂起的 listSelector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 android: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 的顶部或底部.我将不胜感激.

Selecting works fine, but when I start scrolling, listSelector will randomly hang to top or bottom of ListView. I would appreciate any help.

推荐答案

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

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.

您使用的代码:

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

应该用作:

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

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

The above written drawable should be enclosed in the selector tag.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆