列表视图选择彩色的背景和连锁反应 [英] Listview selector with colored background and ripple effect

查看:258
本文介绍了列表视图选择彩色的背景和连锁反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准的ListView 选择在Android L移动开发者preVIEW使用 colorControlHighlight 有关触摸的连锁反应,并具有透明背景的非聚焦状态。

Standard ListView selector in android L developer preview uses colorControlHighlight for the ripple effect on touch and has a transparent background in unfocused state.

我想定义一个拥有彩色的背景,仍然显示了与同一高亮显示颜色触摸的连锁反应一个的ListView 项。现在,如果我定义以下绘制:

I would like to define a ListView item that has a colored background and still shows the ripple effect on touch with the same highlight color. Now, if I define the following drawable:

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?android:colorControlHighlight">
    <item android:drawable="@color/my_background_color"/>
</ripple>

它的工作原理,但纹波在的ListView 项,中间不管触摸位置的开始。如果我使用相同的背景的ListView ,例如外为的LinearLayout ,它像预期(纹波开始于触摸位置)。

it works, but the ripple starts in the middle of the ListView item, regardless of the touch position. If I use the same background outside of the ListView, e.g. for a LinearLayout, it works like expected (the ripple starts on the touch position).

推荐答案

我已经成功地获得单独着色列表项,同时保持了连锁反应。用你拥有的任何适配器设置列表项的背景和设置列表视图显示在顶部的选择:

I've managed to get individually colored list items while maintaining the ripple effect. Set the background of your list items using whatever adapter you have and set the listview to show the selector on top:

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawSelectorOnTop="true" />

这将绘制背景上面的连锁反应。

This will draw the ripple effect above the background.

这篇关于列表视图选择彩色的背景和连锁反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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