CardView的使用
2016-07-26 19:37
295 查看
CardView也是一个容器类布局,开发者可以定义卡片的大小与视图的高度
,并设置圆角的角度。首先你需要在项目中引用com.android.support:
cardview-v7:21.+的依赖。然后在布局文件中引入一个新的名字空间--
xmlns:card_view=http://schemas.android.com/apk/res-auto,这样才可以通过
自定义的名字来引用它的两个属性。card_view:cardBackgroundColor="颜色"和
card_view:cardCornerRadius="8dp"。第一个设置背景颜色,第二个设置圆角的角度。
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
tools:context="com.shuaijie.jiang.recycleviewdemo.MainActivity">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="100dp"
android:layout_height="100dp"
card_view:cardBackgroundColor="#1f38f7"
card_view:cardCornerRadius="30dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="CardView"
android:textColor="#ffffff" />
</android.support.v7.widget.CardView>
</LinearLayout>
在使用CardView时,如果给CardView添加点击效果,要在里面的布局中加,不要在CardView上设置属性。
例如
在CardView中TextView加上背景,就会出现水波纹的效果。
,并设置圆角的角度。首先你需要在项目中引用com.android.support:
cardview-v7:21.+的依赖。然后在布局文件中引入一个新的名字空间--
xmlns:card_view=http://schemas.android.com/apk/res-auto,这样才可以通过
自定义的名字来引用它的两个属性。card_view:cardBackgroundColor="颜色"和
card_view:cardCornerRadius="8dp"。第一个设置背景颜色,第二个设置圆角的角度。
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
tools:context="com.shuaijie.jiang.recycleviewdemo.MainActivity">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="100dp"
android:layout_height="100dp"
card_view:cardBackgroundColor="#1f38f7"
card_view:cardCornerRadius="30dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="CardView"
android:textColor="#ffffff" />
</android.support.v7.widget.CardView>
</LinearLayout>
在使用CardView时,如果给CardView添加点击效果,要在里面的布局中加,不要在CardView上设置属性。
例如
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" card_view:cardBackgroundColor="@color/colorAccent" card_view:cardCornerRadius="10dp" card_view:cardElevation="10dp"> <TextView android:id="@+id/rv_item_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" android:gravity="center" android:textSize="20sp" /> </android.support.v7.widget.CardView>
在CardView中TextView加上背景,就会出现水波纹的效果。
相关文章推荐
- android事件拦截处理机制详解
- 什么鬼,又不知道怎么命名class了
- ue4 创建c++工程失败解决方案
- 26. Remove Duplicates from Sorted Array
- DDR Layout Guide-DDR布线规则与过程
- 27. Remove Element
- 顺序表应用1:多余元素删除之移位算法
- 24. Swap Nodes in Pairs
- 2016夏季练习——类次小生成树
- 51Nod-1183-编辑距离
- Python中的序列相机和相乘
- [SCU4438] Censor [2015 Sichuan Province Contest Final C]
- HDU 3363 Ice-sugar Gourd
- Java实现HTML页面转PDF解决方案
- MyBatis和Hibernate相比,优势在哪里?
- 21. Merge Two Sorted Lists
- quartz动态定时任务
- HDU 2141 Can you find it?(二分)
- 20. Valid Parentheses
- DDR Layout Guide-DDR内存布线指导