Android控件CardView实现卡片布局
作者:简单不一定不好 发布时间:2022-12-05 02:10:32
标签:Android,CardView,卡片布局
CardView介绍
CardView是Android 5.0系统引入的控件,相当于FragmentLayout布局控件然后添加圆角及阴影的效果;CardView被包装为一种布局,并且经常在ListView和RecyclerView的Item布局中,作为一种容器使用。CardView应该被使用在显示层次性的内容时;在显示列表或网格时更应该被选择,因为这些边缘可以使得用户更容易去区分这些内容。
使用
先看效果
首先在build.gradle文件添加依赖库
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
}
布局文件main.html文件下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<ImageView
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:scaleType="centerCrop"
android:src="@drawable/sng" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="棒冰行动"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="棒冰行动,公益传播设计夏令营" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
在MainActivity.java下文件
public class MainActivity extends AppCompatActivity {
private CardView cardView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cardView = (CardView)findViewById(R.id.cardView);
cardView.setRadius(8);//设置图片圆角的半径大小
cardView.setCardElevation(8);//设置阴影部分大小
cardView.setContentPadding(5,5,5,5);//设置图片距离阴影大小
}
}
好,已结束CardView难度不大,当是实用性及及效果是非常棒的,值得你拥有!
来源:https://blog.csdn.net/u010498248/article/details/52524053?utm_source=blogxgwz7


猜你喜欢
- 事件缘由:一个主项目“图说美物”,另外一个子功能是品牌商的入驻功能,是跟主项目分开的项目,为了共享登录的用户信息,而实现session共享,
- 本文实例为大家分享了Unity3D实现批量下载图片功能的具体代码,供大家参考,具体内容如下下一篇文章试试用线程下载代码如下using Sys
- 倒序拼接字符串@ApiOperation("分页查询") @GetMapping(value
- 文件格式分别如下 package txtobject ReadTxt {def readFromTxtBy
- 一>实现功能在实验二中我们已经实现了在类微信界面添加recyclview并添加相应的imageview,本次实验就是在recyclvi
- 1.application.ymlserver: port: 8184spring: application: &n
- 随着时间的推移现在的软件要求显示的内容越来越多,所以要在小的屏幕上能够更好的显示更多的内容,首先我们会想到底部菜单栏,但是有时候像今日头条新
- 本文实例为大家分享了Android刷新加载框架的具体代码,供大家参考,具体内容如下1.定义一个接口控制下拉和上拉public interfa
- ProgressBar有2个子控件:SeekBar 拖动条控件RatingBar 星级评分控
- 现在许多流行的软件中都有欢迎界面,今天就介绍一下欢迎界面的制作,由于界面涉及到页面的滑动,因此要采用ViewPager,sdk在4.0一下的
- 方法一:res/values文件夹下建立styles.xml:<?xml version=“1.0″ encoding=“utf-8″
- 实现形式elevationMaterial Design提供了View的阴影效果设置。主要由两个属性决定:elevation和transla
- 在 C# WPF开发中颜色对话框控件(ColorDialog)用于对界面中的背景、文字…(拥有颜色属性的所有控件)设置
- SpringBoot 如何进行参数校验在日常的接口开发中,为了防止非法参数对业务造成影响,经常需要对接口的参数做校验,例如登录的时候需要校验
- 前言当初年少懵懂,那年夏天填志愿选专业,父母听其他长辈说选择计算机专业好。从那以后,我的身上就有了计院深深的烙印。从寝室到机房,从机房到图书
- 为了让大家知道下面内容是否是自己想要的,我先发效果图。好了,那就开始贴代码了以下为一个按钮的事件,为裁剪准备图片、裁剪路径、保存路径priv
- 1、使用第三方类库 HtmlAgilityPack官方网址:https://html-agility-pack.net/?z=codeple
- mybatis多个区间处理如图:要实现车辆数不同区间查询条件思路a.前端传数组,数组里面放"1-5"String类型值
- IntroC# 9 中进一步增强了模式匹配的用法,使得模式匹配更为强大,我们一起来了解一下吧SampleC# 9 中增强了模式匹配的用法,增
- 当对象间存在一对多关系时,则使用观察者模式(Observer Pattern)。比如,当一个对象被修改时,则会自动通知依赖它的对象。观察者模