android - 对 androidx.cardview.widget.CardView 的涟漪效应

标签 android android-cardview

我想在点击卡片 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/

相关文章:

android - 在 CardView 中使用 ConstraintLayout

android - "Ugly"Pre-Lollipop 设备上的 CardView

android - 错误 : Failed to open database '/storage/emulated/0/database//db.sqlite'

c# - Unity Android 中的文件观察者/观察者?

java - 来自 URL 的 JSON 序列化总是返回 NULL

java - 单个卡片 View 上的随机数量的 TextView 不起作用

java - 找不到 Symbol 类 ActionBarActivity(Android 回收 View )

java - CardView 滑动操作 - Material - Android Java

java - ANDROID - 通过 tcp 套接字将屏幕截图从 java 发送到 android

android - 继续在构造函数上出现 NullPointerException 错误