安卓开发笔记(三十五):Cardview的简单使用

本文详细介绍了Cardview在安卓界面设计中的使用方法,包括布局代码示例和必要的库引入,展示了如何创建美观的卡片式UI元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安卓开发笔记(三十五):Cardview的简单使用

首先上图:

我们可以看到上面这个我所编写的界面上,战狼这一个模块则使用了cardview控件,下面我们来看看它是怎么使用的:
这里是cardview在线性布局下的的布局代码:

 <android.support.v7.widget.CardView
        android:id="@+id/cv3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        app:cardBackgroundColor="#c4c6c8"
        app:cardCornerRadius="10dp"
        app:cardElevation="10dp"
        app:cardPreventCornerOverlap="true"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:layout_width="160dp"
            android:layout_height="80dp"
            android:src="@drawable/timg" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="170dp"
            android:textColor="#000000"
            android:text="战狼2"
            android:textSize="20sp"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="170dp"
            android:text="感受中华民族的崛起!为中华复兴而奋斗!"
            android:textColor="#000000"
            android:layout_marginTop="40dp"/>

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

十分容易就可以搞定了,但是不要忘记了需要在build.gradle文件下使用我们引入的库哈:

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

上面这行代码是必不可少的啦!

posted @ 2019-05-15 11:31 Geeksongs 阅读( ...) 评论( ...) 编辑 收藏
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值