cardview的使用

来源:互联网 发布:公知什么意思 编辑:程序博客网 时间:2024/06/02 03:41

依赖

    compile 'com.android.support:cardview-v7:24.2.0'
item的布局最外层包裹 为了 大家方便看 我就全粘贴过来了

布局中添加

<?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:layout_width="match_parent"        android:layout_height="match_parent"    app:cardUseCompatPadding="true"        android:foreground="?attr/selectableItemBackground"        app:cardElevation="4dp"   >        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="horizontal"            android:padding="5dp">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_margin="5dp"                android:src="@mipmap/music_default_bg" />            <LinearLayout                android:layout_width="0dp"                android:layout_height="wrap_content"                android:layout_marginLeft="5dp"                android:layout_marginTop="5dp"                android:layout_weight="1"                android:orientation="vertical">                <TextView                    android:id="@+id/tv_title"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:text="歌曲名字" />                <TextView                    android:id="@+id/tv_artist"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:text="艺术家"                    android:textColor="#ffcccccc" />            </LinearLayout>            <TextView                android:id="@+id/tv_size"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_margin="5dp"                android:text="3.0MB"                android:textColor="#ffcccccc"                android:textSize="16sp" />        </LinearLayout>    </android.support.v7.widget.CardView>
其他属性

app:cardBackgroundColor这是设置背景颜色 app:cardCornerRadius这是设置圆角大小 app:cardElevation这是设置z轴的阴影    同时决定了间距 app:cardMaxElevation这是设置z轴的最大高度值 app:cardUseCompatPadding是否使用CompatPadding app:cardPreventCornerOverlap是否使用PreventCornerOverlap app:contentPadding 设置内容的padding app:contentPaddingLeft 设置内容的左padding app:contentPaddingTop 设置内容的上padding app:contentPaddingRight 设置内容的右padding app:contentPaddingBottom 设置内容的底padding


复制下面代码 阴影效果

    android:foreground="?attr/selectableItemBackground"    app:cardBackgroundColor="@color/white"    app:cardElevation="2dp"    app:cardUseCompatPadding="true"    app:contentPaddingBottom="5dp"    app:contentPaddingTop="5dp"


0 0
原创粉丝点击