0
点赞
收藏
分享

微信扫一扫

[Android Material Design]组件06 - CardView

墨春 2022-03-23 阅读 29

文章目录

效果图

CardView

关键代码

<!-- 添加android:clickable属性后,点击cardview会有水波纹效果 -->
<androidx.cardview.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:foreground="?android:attr/selectableItemBackground"
    android:clickable="true"
    app:cardBackgroundColor="@color/purple_500"
    app:cardCornerRadius="10dp"
    app:cardElevation="10dp"
    app:contentPadding="30dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="CardView测试样例!"
        android:textColor="@android:color/background_light" />
</androidx.cardview.widget.CardView>

CardView是在Android5.0上新增新控件,是在FrameLayout的基础上添加了圆角和阴影效果,实现了立体感的控件。CardView可以作为容器,一般应用在ListViewRecyclerViewItem布局中,Item布局可以再新增其他控件。

CardView常用属性如下:

属性含义
app:cardBackgroundColor背景色
app:cardCornerRadius边缘弧度数
app:cardElevation高度
app:cardMaxElevation最大高度
app:cardUseCompatPadding设置内边距
app:contentPadding卡片边界距离内部的距离

源码地址

https://github.com/yurensan/MaterialDesignDemo

举报

相关推荐

0 条评论