Android 仅对布局中项目的选定项目产生涟漪效应
我有一个布局列表,只想在选定的项目上显示涟漪效应。但是,当前代码将突出显示父布局中的每个布局。感谢您的帮助Android 仅对布局中项目的选定项目产生涟漪效应,android,android-layout,android-styles,Android,Android Layout,Android Styles,我有一个布局列表,只想在选定的项目上显示涟漪效应。但是,当前代码将突出显示父布局中的每个布局。感谢您的帮助 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingTop="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="15dp">
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_alignParentBottom="true"
android:background="#6792" />
<LinearLayout
android:background="@drawable/layout_list_item_selector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="35dp"
android:gravity="center_vertical"
android:text="Item # 1" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_alignParentBottom="true"
android:background="#6792" />
<LinearLayout
android:background="@drawable/layout_list_item_selector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="35dp"
android:gravity="center_vertical"
android:text="Item # 2" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_alignParentBottom="true"
android:background="#6792" />
<LinearLayout
android:background="@drawable/layout_list_item_selector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="35dp"
android:gravity="center_vertical"
android:text="Item # 3" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_alignParentBottom="true"
android:background="#6792" />
</LinearLayout>
以下是v21以下和以上ripple effect的背景样式
布局\列表\项目\选择器.xml
布局列表项选择器.xml(v-21)
使用此库
这给了安卓棒棒糖效果,也包括你想要的涟漪效果
使用此库
这给了安卓棒棒糖效果,也包括你想要的涟漪效果
我通过需要设置后台布局.setBackgroundResource(R.drawable.layout\u list\u item\u selector)的代码修复了它 我通过需要设置backgrowth.setBackgroundResource(R.drawable.layout\u list\u item\u选择器)的代码来修复它 我通过需要设置background.setBackgroundResource(R.drawable.layout\u list\u item\u选择器)的代码来修复它;我通过需要设置background.setBackgroundResource(R.drawable.layout\u list\u item\u选择器)的代码来修复它;
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#ffc20e" android:state_pressed="true"/>
<item android:drawable="#ffffff"/>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ffc20e">
<item
android:id="@android:id/mask"
android:drawable="#ffffff" />
</ripple>