Android---MaterialCardView的使用

Android—MaterialCardView的使用

image

我们的征程是星辰大海,而非人间烟尘

演示

MDCard

xml布局

<com.google.android.material.card.MaterialCardView
        android:id="@+id/materialCardView2"
        android:layout_width="170dp"
        android:layout_height="170dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:clickable="true"    // 是否可点击
        app:cardCornerRadius="20dp"  //  圆角半径
        app:cardElevation="20dp"  //  阴影范围
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/banner"
        app:rippleColor="#A8C0EC"    //  点击阴影特效的颜色
        app:state_dragged="true">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="140dp"
            android:scaleType="centerCrop"
            android:src="@drawable/quesans" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="140dp"
            android:text="问答"
            android:textColor="@color/black"
            android:textFontWeight="@android:integer/config_mediumAnimTime"
            android:textSize="18sp" />
    </com.google.android.material.card.MaterialCardView>

image

其他的属性

特征相关属性
Borderapp:strokeColor app:strokeWidth
Checkableandroid:checkable
Checked Iconapp:checkedIcon app:checkedIconTint
Foreground Colorapp:cardForegroundColor
Ripple Colorapp:rippleColor

当然你还可以在Java/Kotlin代码中使用一些方法:

void setCheckable (boolean checkable)//设置是否可以选择
void setChecked (boolean checked)//选中的状态
void setCheckedIcon (Drawable checkedIcon)//选中图标的样式
void setCheckedIconResource (int id)//选中图标的样式
void setDragged (boolean dragged)//是否可拖动
void setRippleColor (ColorStateList rippleColor)//波纹效果的颜色
void setStrokeColor (int strokeColor)//卡片边的颜色
void setStrokeWidth (int strokeWidth)//卡片边的宽带
void toggle ()//控制checkable的开关
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Liknana

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

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

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

打赏作者

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

抵扣说明:

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

余额充值