cardview的使用

依赖

    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"


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安果移不动

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值