我想在点击卡片 View 时添加链式 react ,奇怪的是它没有出现?
这里可能出了什么问题?
<?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>
//我有一个线性布局,在 cardview 中有三个 textview。
回收 View :
<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>
谢谢!
最佳答案
不要在 CardView
中使用任何 background/foreground
。如果您使用任何背景颜色,则只需添加 app:cardBackgroundColor="@color/cardBackgroundColor
。从 CardView
中删除任何 padding
。使用margin
项目之间的空间。
现在,对于 CardView
中的涟漪效果,只需在 CardView
中添加一个直接的子布局。 设置 android:background ="?attr/selectableItemBackground"
在子布局中。如果需要,在 child 中添加任何必要的 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>
关于android - 对 androidx.cardview.widget.CardView 的涟漪效应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57585239/