San*_*air 2 android android-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>
Run Code Online (Sandbox Code Playgroud)
// 我在cardview中有一个带有三个textview的线性布局。
回收者视图:
<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>
Run Code Online (Sandbox Code Playgroud)
谢谢!
不要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>
Run Code Online (Sandbox Code Playgroud)