Android Material Design 之 CardView卡片式布局


效果图

在这里插入图片描述


一、CardView是什么?

CardView是一个视图容器,继承自FrameLayout,CardView像一张卡片,有阴影和圆角,这些属性也可以添加到其他视图组中。

二、使用步骤

1.布局

代码如下(示例):


    <androidx.cardview.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_margin="10dp"
        android:padding="10dp"
        app:cardBackgroundColor="@color/white"
        app:cardElevation="10dp"
        app:cardCornerRadius="5dp"
        app:contentPadding="5dp" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/img"
                android:layout_width="120dp"
                android:layout_height="match_parent"
                android:background="@mipmap/fruit"/>

            <TextView
                android:layout_marginLeft="20dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="水果水果水果水果水果水果水果水果"
                android:textSize="14sp"
                android:textColor="#333"/>
        </LinearLayout>


    </androidx.cardview.widget.CardView>

2.属性

app:cardElevation:阴影的大小
app:cardCornerRadius:圆角的大小
app:contentPadding:卡片里内容距卡片边距的距离
app:cardBackgroundColor:卡片背景颜色


总结

CardView卡片式布局 可以使用于 商品列表 、明信片等

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值