1.CardView介绍
- CardView是一种卡片视图,主要是以卡片形式显示内容。
- CardView是继承自FrameLayout
- CardView实现在一个卡片布局中显示相同的内容,卡片布局可以设置圆角和阴影,还可以布局其他的View。
- CardView即可作为一般的布局使用,也可以作为ListView和RecyclerView的Item使用。
dependencies {
compile 'com.android.support:cardview-v7:23.1.1'
}
在Eclipse中引用
android-sdk/extras/android/support/v7/cardview目录下面有libs,里面有jar包,引用此jar包
2.CardView使用
<span style="font-size:18px;"><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="match_parent"
android:orientation="horizontal"
card_view:cardBackgroundColor="@android:color/black"
card_view:cardCornerRadius="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="1dp">
<ImageView
android:id="@+id/iv_pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:scaleType="centerCrop" />
</RelativeLayout>
</android.support.v7.widget.CardView></span>
3.CardView属性介绍
<span style="font-size:18px;">android:cardCornerRadius
在xml文件中设置card圆角的大小</span>
<span style="font-size:18px;">CardView.setRadius
在代码中设置card圆角的大小</span>
<span style="font-size:18px;">android:cardBackgroundColor
在xml文件中设置card背景颜色</span>
<span style="font-size:18px;">android:elevation
在xml文件中设置阴影的大小</span>
<span style="font-size:18px;">card_view:cardElevation
在xml文件中设置阴影的大小</span>
<span style="font-size:18px;">card_view:cardMaxElevation
在xml文件中设置阴影最大高度</span>
<span style="font-size:18px;">card_view:cardCornerRadius
在xml文件中设置卡片的圆角大小</span>
<span style="font-size:18px;">card_view:contentPadding
在xml文件中设置卡片内容于边距的间隔</span>
<span style="font-size:18px;">card_view:contentPaddingBottom
在xml文件中设置卡片内容于下边距的间隔</span>
<span style="font-size:18px;">card_view:contentPaddingTop
在xml文件中设置卡片内容于上边距的间隔</span>
<span style="font-size:18px;">card_view:contentPaddingLeft
在xml文件中设置卡片内容于左边距的间隔</span>
<span style="font-size:18px;">card_view:contentPaddingRight
在xml文件中设置卡片内容于右边距的间隔</span>
<span style="font-size:18px;">card_view:contentPaddingStart
在xml文件中设置卡片内容于边距的间隔起始</span>
<span style="font-size:18px;">card_view:contentPaddingEnd
在xml文件中设置卡片内容于边距的间隔终止</span>
<span style="font-size:18px;">card_view:cardUseCompatPadding
在xml文件中设置内边距,V21+的版本和之前的版本仍旧具有一样的计算方式</span>
<span style="font-size:18px;">card_view:cardPreventConrerOverlap
在xml文件中设置内边距,在V20和之前的版本中添加内边距,这个属性为了防止内容和边角的重叠</span>
4.CardView注意事项
1.默认情况,CardView是不可点击的,并且没有任何的触摸反馈效果。
2.触摸反馈动画在用户点击CardView时可以给用户以视觉上的反馈。
3.实现这种行为,你必须提供一下属性:android:clickable和android:foreground(波纹点击效果)。
欢迎留言和评论!
博客地址:http://blog.csdn.net/caihongdao123下一篇 Android 5.0+ 解析(三)Palette类