佛山手机网站设计制作,企业管理系统oa,江苏建设工程信息网网址,做网站的主营业务目录
一、CardView
1.1 导入material库
1.2 属性
二、使用(效果)
2.1 圆角卡片效果
2.2 阴影卡片效果
2.3 背景 2.3.1 设置卡片背景(app:cardBackgroundColor) 2.3.2 内嵌布局#xff0c;给布局设置背景色
2.4 进阶版 2.4.1 带透明度 2.4.2 无透明度 一、CardView 顾名…目录
一、CardView
1.1 导入material库
1.2 属性
二、使用(效果)
2.1 圆角卡片效果
2.2 阴影卡片效果
2.3 背景 2.3.1 设置卡片背景(app:cardBackgroundColor) 2.3.2 内嵌布局给布局设置背景色
2.4 进阶版 2.4.1 带透明度 2.4.2 无透明度 一、CardView 顾名思义就是卡片布局。现在卡片布局越来越普及了以前都是各种shape来实现卡片效果现在可以直接用控件来实现是不是美滋滋CardView实用性还是比较强的一起来试试吧 1.1 导入material库
implementation com.google.android.material:material:1.10.0material:1.10.0 要求SDK大于等于34如果不打算兼容那么高的建议降低至 1.8.0 不影响 CardView 的使用。 CardView继承自FrameLayout可以让我们使用类似卡片布局来显示一致性效果的内容。同时卡片还可以包含圆角和阴影效果。
1.2 属性 app:cardBackgroundColor 设置背景颜色 app:cardCornerRadius 设置圆角大小不要圆角设置为0 app:cardElevation 设置z轴的阴影不需要阴影设置为0 app:cardMaxElevation 设置z轴的最大高度值 app:contentPadding 设置padding app:contentPaddingLeft app:contentPaddingTop app:contentPaddingRight app:contentPaddingBottom 需要注意的是这里的前缀是 app 而不是 android 。 二、使用(效果)
2.1 圆角卡片效果 默认是带点阴影效果的。 androidx.cardview.widget.CardViewandroid:layout_widthmatch_parentandroid:layout_margin10dpandroid:backgroundcolor/purple_200app:cardCornerRadius10dpapp:contentPadding20dpandroid:layout_heightwrap_contentTextViewandroid:layout_widthwrap_contentandroid:text圆角 CardView android:textColorcolor/blackandroid:layout_heightwrap_content//androidx.cardview.widget.CardView2.2 阴影卡片效果 androidx.cardview.widget.CardViewandroid:layout_widthmatch_parentandroid:layout_margin10dpapp:cardCornerRadius10dpapp:cardElevation20dpandroid:layout_heightwrap_contentTextViewandroid:layout_widthwrap_contentandroid:layout_gravitycenterandroid:layout_margin20dpandroid:text阴影 CardViewandroid:textColorcolor/blackandroid:layout_heightwrap_content//androidx.cardview.widget.CardView2.3 背景 2.3.1 设置卡片背景(app:cardBackgroundColor) androidx.cardview.widget.CardViewandroid:layout_widthmatch_parentandroid:layout_margin10dpapp:cardBackgroundColorcolor/purple_200app:cardCornerRadius10dpapp:cardElevation20dpandroid:layout_heightwrap_contentLinearLayoutandroid:layout_widthmatch_parentandroid:orientationverticalandroid:layout_heightwrap_contentTextView.../TextView...//LinearLayout/androidx.cardview.widget.CardView2.3.2 内嵌布局给布局设置背景色 androidx.cardview.widget.CardViewandroid:layout_widthmatch_parentandroid:layout_margin10dpapp:cardCornerRadius10dpapp:cardElevation20dpandroid:layout_heightwrap_contentLinearLayoutandroid:layout_widthmatch_parentandroid:orientationverticalandroid:backgroundcolor/purple_200android:layout_heightwrap_contentTextView.../TextView...//LinearLayout/androidx.cardview.widget.CardView2.4 进阶版 同时设置 app:cardBackgroundColor 和 android:background。 2.4.1 带透明度 androidx.cardview.widget.CardViewapp:cardBackgroundColor#44ff0000android:background#440000ff...TextViewandroid:background#440000ff//androidx.cardview.widget.CardView2.4.2 无透明度 androidx.cardview.widget.CardView...app:cardBackgroundColor#ff0000android:background#00ff00TextView...android:background#0000ff//androidx.cardview.widget.CardViewandroid:background明显会被app:cardBackgroundColor消费(覆盖)掉