Android CardView简单介绍

一、介绍:CardView可以实现卡片布局,拥有圆角和阴影效果

1.导入包

implementation 'com.android.support:cardview-v7:27.1.1'

一般配合RecyclerView ,和Glide(图片加载库)使用

implementation 'com.android.support:recyclerview-v7:27.1.1'

/*图片加载库*/

compile 'com.github.bumptech.glide:glide:3.7.0'

2.基本用法,其实也是一个FrameLayout布局

app:cardCornerRadius="4dp"            设置圆角

android:elevation="5dp"                    设置阴影/高度

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardCornerRadius="4dp"
    android:elevation="5dp">

    <TextView
        android:id="@+id/info_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</android.support.v7.widget.CardView>

3.方法

    //实例化

    cardView = (CardView)findViewById(R.id.cardView);

    cardView.setRadius(8);                    //设置图片圆角的半径大小

    cardView.setCardElevation(8);        //设置阴影部分大小

    cardView.setContentPadding(5,5,5,5);        //设置图片距离阴影大小

CardView难度不大,不举例子了



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
CardViewAndroid Support Library中的一个控件,可以帮助开发人员创建具有阴影和圆角边框的卡片视图。它可以用来展示一些信息,如图片、文本、按钮等,使应用程序的UI更加美观和现代化。 在Android Studio中使用CardView,需要在build.gradle文件中添加以下依赖: ``` dependencies { implementation 'com.android.support:cardview-v7:28.0.0' } ``` 然后,在布局文件中添加CardView控件: ```xml <android.support.v7.widget.CardView android:id="@+id/cardview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp" app:cardCornerRadius="8dp" app:cardElevation="4dp" app:cardUseCompatPadding="true"> <!--在CardView中添加其他控件--> </android.support.v7.widget.CardView> ``` 其中,app:cardCornerRadius属性用于设置圆角半径,app:cardElevation属性用于设置阴影大小,app:cardUseCompatPadding属性用于启用兼容性填充。 可以在CardView中添加其他控件,如ImageView、TextView、Button等。例如: ```xml <android.support.v7.widget.CardView android:id="@+id/cardview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp" app:cardCornerRadius="8dp" app:cardElevation="4dp" app:cardUseCompatPadding="true"> <ImageView android:layout_width="match_parent" android:layout_height="200dp" android:src="@drawable/image"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="标题" android:textSize="20sp" android:padding="16dp"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮" android:layout_margin="16dp"/> </android.support.v7.widget.CardView> ``` 这样就可以创建一个简单CardView了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Amarao

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

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

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

打赏作者

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

抵扣说明:

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

余额充值