android-cardview简单使用

cardview是5.0以上版本的控件,是一个卡片式布局,继承framlayout,但是可以使用兼容包老兼容4.0以上的设备。

测试环境是android studio

1.加入依赖:

<span style="font-size:14px;">compile 'com.android.support:cardview-v7:21.0.3'</span>

2.写布局:

<span style="font-size:14px;"><android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardCornerRadius="4dp"
    app:cardBackgroundColor="@color/style_color_primary">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hello cardview!"/>
    </LinearLayout>


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

注意:这里有两个属性cardCornerRadius和cardBackgroundColor,已经基本上见名知其意了,第一个是圆角半径,第二个是背景颜色。

还有一个elevator属性,但是只有在5.0以上版本才能显示出来效果啦。

  • 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
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值