art*_*nig 55 android listview material-design rippledrawable android-5.0-lollipop
ListView
android L开发人员预览中的标准选择器colorControlHighlight
用于触摸时的涟漪效果,并且在未聚焦状态下具有透明背景.
我想定义一个ListView
具有彩色背景的项目,并且仍然使用相同的高亮颜色显示触摸时的涟漪效果.现在,如果我定义以下drawable:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:drawable="@color/my_background_color"/>
</ripple>
Run Code Online (Sandbox Code Playgroud)
它起作用,但ListView
无论触摸位置如何,纹波都从物品的中间开始.如果我使用相同的背景ListView
,例如a LinearLayout
,它就像预期的那样工作(波纹从触摸位置开始).
dya*_*cat 126
我设法获得单独的彩色列表项目,同时保持涟漪效果.使用您拥有的任何适配器设置列表项的背景,并设置listview以在顶部显示选择器:
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="true" />
Run Code Online (Sandbox Code Playgroud)
这将在背景上绘制涟漪效果.
据我所知,这个bug仅在Android 5.0中,而不是5.1.诀窍似乎是使用Drawable#setHotspot作为谷歌开发提示到这里https://twitter.com/crafty/status/561768446149410816(因为模糊的Twitter提示是一种很好的文档形式!)
假设你有一个像这样的行布局
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/row_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="?attr/selectableItemBackground">
.... content here .....
</LinearLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
以下对我有用
row.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.findViewById(R.id.row_content)
.getBackground()
.setHotspot(event.getX(), event.getY());
return(false);
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
46684 次 |
最近记录: |