1. 程式人生 > >CardView定義陰影、點選水波紋、圓角

CardView定義陰影、點選水波紋、圓角

一般使用在recyclerView中,給每個Item項新增需要的效果,例如陰影,圓角,還有點選的水波紋等。

寫法就是新增V7包中的CardView作為根佈局即可:

效果如下:

全部程式碼如下,主要就是設定CardView的屬性:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/right_container"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:clickable="true"
    android:focusable="true"
    app:cardCornerRadius="20dp"
    android:foreground="?android:attr/selectableItemBackground"
    app:cardElevation="12dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="28dp"
            android:text="hehe"
            android:textSize="16sp"
            android:textStyle="bold" />

    </RelativeLayout>
</android.support.v7.widget.CardView>