Android开发 之 CardView及常用属性

来源:互联网 发布:linux acl chown 区别 编辑:程序博客网 时间:2024/05/17 01:00

CardView及常用属性


引入 compile 'com.android.support:cardview-v7:21.0.+'

app:cardElevation 属性向下兼容 为了统一不同系统版本的视觉效果,Google 针对 SDK 21 以下的系统给 CardView 加入一个 Elevation 兼容(即 XML 中的 app:cardElevation 和 Java 代码中的 setCardElevation)。

cardElevation 阴影的大小cardMaxElevation 阴影最大高度cardCornerRadius 卡片的圆角大小contentPadding 卡片内容于边距的间隔 contentPaddingBottom contentPaddingTop contentPaddingLeft contentPaddingRight contentPaddingStart contentPaddingEndcardUseCompatPadding 设置内边距,V21+的版本和之前的版本仍旧具有一样的计算方式**:cardPreventConrerOverlap 在V20和之前的版本中添加内边距,这个属性为了防止内容和边角的重叠**



<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:id="@+id/cardview"    android:layout_width="match_parent"    android:layout_height="200dp"    android:layout_margin="10dp"    app:cardElevation="10dp"    app:cardCornerRadius="10dp" >        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <ImageView                android:id="@+id/iv_icon"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_margin="5dp"                />            <TextView                android:id="@+id/tv_name"                android:layout_width="wrap_content"                android:layout_height="wrap_content" />        </LinearLayout>    </android.support.v7.widget.CardView>


原创粉丝点击