Android CardView 的使用
2016-05-27 16:51
831 查看
CardView
CardView继承至FrameLayout类,可以在一个卡片布局中一致性的显示内容,卡片可以包含圆角和阴影。CardView是一个Layout,可以布局其他View。CardView的 常用属性
card_view:cardElevation 阴影的大小card_view:cardMaxElevation 阴影最大高度
card_view:cardBackgroundColor 卡片的背景色
card_view:cardCornerRadius 卡片的圆角大小
card_view:contentPadding 卡片内容于边距的间隔
card_view:contentPaddingBottom
card_view:contentPaddingTop
card_view:contentPaddingLeft
card_view:contentPaddingRight
card_view:contentPaddingStart
card_view:contentPaddingEnd
card_view:cardUseCompatPadding 设置内边距,V21+的版本和之前的版本仍旧具有一样的计算方式
card_view:cardPreventConrerOverlap 在V20和之前的版本中添加内边距,这个属性为了防止内容和边角的重叠
demo演示
这个demo 通过RecyclerView和CardView实现了瀑布流的效果,你可以看下前面写的一篇文章,有其余的代码.Android RecyclerView 实现瀑布流效果
使用cardview将每个RecyclerView的组件包裹起来,即可实现卡片效果.
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content" android:layout_height="wrap_content" app:cardBackgroundColor="#22eec900" app:cardCornerRadius="10dp" app:cardMaxElevation="1dp" app:cardElevation="1dp"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <!-- adjustViewBounds 是否保持原图宽高比 --> <!-- 中心缩放 --> <ImageView android:id="@+id/id_iv_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustViewBounds="true" android:contentDescription="@string/image" android:scaleType="centerCrop" /> <TextView android:id="@+id/id_tv_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" /> </LinearLayout> </android.support.v7.widget.CardView>
相关文章推荐
- Android Studio 项目导入
- android 基础 加密 简易加密BASE64Decoder
- Android Studio 安装完成,启动时一直download Components解决办法
- 自定义view实现涂鸦(画板)功能
- Android NDK 安装与配置
- Android开发之Broadcast Receiver 详解
- Android下拉刷新上拉加载控件,对所有View通用!
- 自定义ButtonButton
- android studio 开发 cordova plugin(组件)的 helloWorld
- Scroller 学习
- Android签名详解(debug和release)
- Android Studio多渠道快速打包
- android led 驱动
- Android下拉列表spinner的实例代码
- Android自定义RadioGroup
- github上的项目导入Android studio出错(整理)
- <Android> Location Service 分析
- android 设置自定义dialog大小无效果
- Android 性能优化(很好的文章)
- Android中RadioButton样式问题