StateListDrawable中的ListView奇怪断色在一定条件下 [英] StateListDrawable in ListView strangely off-colored in certain conditions

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

问题描述

我已创建了TextViews一个ListView作为项目 - 其中大部分具有一定的颜色作为背景,但一些有一个定制@抽拉/形状作为背景(即顶部和底部件,其具有圆角)。 这些背景被设置为国家清单的一部分,提供另一种背景颜色,当项目被窃听。 在ListView的listSelector设置为透明的,而是在项目中包含TextViews设置为可点击。

I have created a ListView with TextViews as items - most of which have a certain color as background, but some have a custom @drawable/shape as background (i.e. the top and bottom items, which have rounded corners). These backgrounds are set as part of state-lists, to provide another background color when the items are tapped. The listSelector of the ListView is set to transparent, and instead the contained TextViews in the items are set to clickable.

ListView控件:

ListView:

<ListView android:id="@+id/allreminders_list" android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:dividerHeight="3px" android:cacheColorHint="#00000000"
android:divider="@color/trans" android:background="@drawable/reminderlist_background"
android:listSelector="@android:color/transparent"/>

ListView的条目:

ListView entry:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"
android:id="@+id/entry_container">
<TextView android:id="@+id/remindername" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="dummy"
android:padding="15dp" android:layout_marginLeft="15px"
android:layout_marginRight="15px" style="@style/ReminderEntry"
android:clickable="true"/>
</RelativeLayout>

中的ListView进入后台的程序化设置:

Programmatical setting of ListView entry background:

if (position == 1)
textViewReminderName
  .setBackgroundResource(R.drawable.reminder_entry_state_top);
else if (position == remindersInSection)
textViewReminderName
  .setBackgroundResource(R.drawable.reminder_entry_state_bottom);
else
textViewReminderName
  .setBackgroundResource(R.drawable.reminder_entry_state);

国家列表顶部的项目(R.drawable.reminder_entry_state_top):

State-list for top items (R.drawable.reminder_entry_state_top):

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/rounded_top_corners_selected" />
<item android:state_selected="true" android:drawable="@drawable/rounded_top_corners_selected" />
<item android:drawable="@drawable/rounded_top_corners" />

形状为未选中的顶级项目(@绘制/ rounded_top_corners):

Shape for unselected top items (@drawable/rounded_top_corners):

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
<solid android:color="@color/entry_background"/>    
<corners android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp" 
 android:topLeftRadius="5dp" android:topRightRadius="5dp"/> 
</shape>

这东西的作品,功能上。但,顶部和底部产品(其具有的形状抽拉作为背景,这是上面示出)稍微改变在某些条件下其颜色:

This stuff works, functionally. BUT, the top and bottom items (which have the shape-drawable as background, which is shown above) change their color slightly under certain conditions:

  • 在向下滚动没有自来水停止滚动
  • 列表之后
  • 单击列表中的任何项目后

这些项目的正确的颜色,当我滚动列表而不删除手指滚动已结束之前才会显示。

The correct color of those items is only shown when I scroll the list without removing the finger before scrolling has ended.

可这有什么可能呢?在路上StateListDrawables present绘制形状的问题吗?

What can this possibly be? A bug in the way StateListDrawables present drawable shapes?

推荐答案

无休止的研究和猜测后,我发现自己的理由:抖动! 通过禁用抖动在国家列表选择,这个问题奇迹般地消失了:

After endless research and guesswork, I've found the reason myself: Dithering! By disabling dithering in the state-list selectors, the problem magically disappeared:

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

似乎抖动仅在特定条件下施加(如上所述),这是不IMHO预期行为,但通过可治疗完全禁用它

It seems that dithering is only applied under certain conditions (as described above) which is IMHO not expected behaviour, yet treatable by disabling it completely.

这篇关于StateListDrawable中的ListView奇怪断色在一定条件下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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