android - androidx.cardview.widget.CardView 上的涟漪效应
问题描述
我正在尝试在点击卡片视图时添加涟漪效果,但奇怪的是它没有出现吗?
这里有什么问题?
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_margin="5dp"
card_view:cardCornerRadius="6dp"
card_view:contentPadding="5dp"
card_view:cardElevation="4dp"
card_view:cardMaxElevation="6dp"
app:ignore="NamespaceTypo">
</androidx.cardview.widget.CardView>
// 我有一个线性布局,卡片视图内有三个文本视图。
回收站视图:
<LinearLayout
android:id="@+id/cardViewLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:visibility="gone">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
谢谢!
解决方案
不要background/foreground
在CardView
. 如果您使用任何背景颜色,那么只需添加app:cardBackgroundColor="@color/cardBackgroundColor
. 从. padding
_ CardView
用于margin
项目之间的空间。
现在,对于 中的涟漪效应CardView
,只需在您的CardView
. android:background="?attr/selectableItemBackground"
在子布局中设置。padding/margin
如果需要,可以在孩子中添加任何必要的内容。
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
card_view:cardCornerRadius="6dp"
card_view:cardElevation="4dp"
card_view:cardMaxElevation="6dp"
app:ignore="NamespaceTypo">
<!-- Child Layout -->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="?attr/selectableItemBackground"
android:orientation="vertical">
<!-- Your content here -->
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
推荐阅读
- python - 使用 sci-kit learn 在 LinearRegression 中查找 p 和 t 值
- python - 使用 pandas python 中的计算对值进行排序
- javascript - 带有“if”条件的 SetInterval() 将值赋给数组
- ios - 如何停止快速检测物体?
- pandas - 由于“日期”列,无法将列表插入数据框中?
- reactjs - 在同一个组件中映射和渲染两个不同的数组 - React
- python-3.x - 如何读取 ibd 文件中的字节数(subprocess.check_output 返回码)
- java - jar 中没有主要清单属性
- png - 使用 binwalk 仅提取一种文件类型
- spring - Spring-Boot:组件的可扩展性