View-CardView

CardView是一个卡片式布局,继承FrameLayout,可以设置圆角和阴影,是控件具有立体感,也可以包含其他的布局容器和控件。

1.配置build.gradle

如果SDK低于5.0,需要引入v7包

dependencies {

compile fileTree(include: ['*.jar'], dir: 'libs')

compile 'com.android.support:appcompat-v7:26.+'

compile 'com.android.support:cardview-v7:26.+'

}

2.cardView使用

<android.support.v7.widget.CardView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="20dp"

app:cardCornerRadius="20dp"

app:cardElevation="20dp"

>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="10dp"

android:text="你好"/>

</android.support.v7.widget.CardView>

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

猜你喜欢

转载自blog.csdn.net/zmesky/article/details/81167059