[Android] Android 卡片式控件CardView的优雅使用

CardView是在安卓5.0提出的卡片式控件

其具体用法如下:

1、在app/build.gradle 文件中添加

compile 'com.android.support:cardview-v7:25.3.1' // 卡片式布局

2、在xml布局文件中使用

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".modules.main.ui.MainActivity"> <android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="20dp"
android:elevation="5dp"
app:cardBackgroundColor="#0000ff"
app:cardCornerRadius="10dp"> <TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="圆角text"/>
</android.support.v7.widget.CardView>
</RelativeLayout>

3、或者 在代码中设置使用

cardView = (CardView)findViewById(R.id.cardView);
    cardView.setRadius(8);                    //设置图片圆角的半径大小
    cardView.setCardElevation(8);        //设置阴影部分大小
    cardView.setContentPadding(5,5,5,5);        //设置图片距离阴影大小

另)  附上它的常见基本属性:
app:cardBackgroundColor这是设置背景颜色
app:cardCornerRadius这是设置圆角大小
app:cardElevation这是设置z轴的阴影
app:cardMaxElevation这是设置z轴的最大高度值
app:cardUseCompatPadding是否使用CompatPadding
app:cardPreventCornerOverlap是否使用PreventCornerOverlap
app:contentPadding 设置内容的padding
app:contentPaddingLeft 设置内容的左padding
app:contentPaddingTop 设置内容的上padding
app:contentPaddingRight 设置内容的右padding
app:contentPaddingBottom 设置内容的底padding

本博客地址: wukong1688

本文原文地址:https://www.cnblogs.com/wukong1688/p/10671941.html

转载请著名出处!谢谢~~

[Android] Android 卡片式控件CardView的优雅使用的更多相关文章

  1. Android常用酷炫控件(开源项目)github地址汇总

    转载一个很牛逼的控件收集帖... 第一部分 个性化控件(View) 主要介绍那些不错个性化的 View,包括 ListView.ActionBar.Menu.ViewPager.Gallery.Gri ...

  2. Android 常用炫酷控件(开源项目)git地址汇总

    第一部分 个性化控件(View) 主要介绍那些不错个性化的 View,包括 ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.P ...

  3. Android Material适配 为控件设置指定背景色和点击波纹效果

    Android Material适配 为控件设置指定背景色和点击波纹效果,有需要的朋友可以参考下. 大部分时候,我们都需要为控件设置指定背景色和点击效果 4.x以下可以使用selector,5.0以上 ...

  4. JS调用Android、Ios原生控件

    在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...

  5. Android开发之日历控件实现

    Android开发之日历控件实现:以下都是转载的. 日历控件 日历控件 日历控件 日历控件

  6. android中的EditView控件

    android中的EditView控件 EditText继承关系:View-->TextView-->EditText ,EditText是可编辑文本框 1.EditText默认情况下,光 ...

  7. Android中通过WebView控件实现与JavaScript方法相互调用的地图应用

    在Android中通过WebView控件,可以实现要加载的页面与Android方法相互调用,我们要实现WebView中的addJavascriptInterface方法,这样html才能调用andro ...

  8. Android 性能优化——之控件的优化

    Android 性能优化——之控件的优化 前面讲了图像的优化,接下来分享一下控件的性能优化,这里主要是面向自定义View的优化. 1.首先先说一下我们在自定义View中可能会犯的3个错误: 1)Use ...

  9. Android 5.0新控件——FloatingActionButton(悬浮按钮)

    Android 5.0新控件--FloatingActionButton(悬浮按钮) FloatingActionButton是5.0以后的新控件,一个悬浮按钮,之所以叫做悬浮按钮,主要是因为自带阴影 ...

随机推荐

  1. 【题解】 bzoj3916: [Baltic2014]friends (字符串Hash)

    题面戳我 Solution 首先长度为偶数可以直接判掉 然后我们可以枚举删的位置,通过预处理的\(hash\),判断剩余部分是否划分成两个一样的 判重要注意,我们把字符串分为三个部分\(L_l+1+L ...

  2. iptables(3)

    ----------------------------iptables企业应用 ****************************单机防火墙列表#!/bin/bash#============ ...

  3. [HAOI2015]按位或(容斥+前缀和)

    题目描述 刚开始你有一个数字0,每一秒钟你会随机选择一个[0,2^n-1]的数字,与你手上的数字进行或(c++,c的|,pascal 的or)操作.选择数字i的概率是p[i].保证0<=p[i] ...

  4. Mysql 系统表

    Information_schema: 1. tables 提供表信息: 表所属数据库,表名,表类型,行数,最大自增数等等.

  5. kafaka quickstart

    http://kafka.apache.org/ http://kafka.apache.org/downloads cd /root/kafuka/kafka_2.12-0.11.0.0 nohup ...

  6. A1046. Shortest Distance

    The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...

  7. [luogu3369][普通平衡树]

    题目链接 思路 模板 只是有几个容易出错的地方 第45行容易忘记 第54行里面的cnt--和siz--容易忘记 第56行是根据id判断不是val 第60行siz--容易忘记 第64行是siz+1不是s ...

  8. vue学习(1)

    前置的准备学习: ES6简单语法: 1.let和const 2.模板字符串 3.箭头函数 4.对象的单体模式 5.es6的面向对象 6.模块化 1.let和const <script type= ...

  9. springmvc 学习笔记

    @Autowired,@RequestMapping,@RequestParam 使用该注解,引入对象时, 可以省略setter getter.减少代码显示. @AutowiredSimService ...

  10. 完美解决windows+ngnix+phpcgi自动退出的问题

    [摘要]在windows下搭建nginx+php环境时,php-cgi.exe会经常性的自动关闭退出,本文介绍通过使用xxfpm进程管理器管理php-cgi.exe. php-cgi.exe在wind ...