像平时我们要实现按钮的圆角(渐变、实心填涂、画笔)都是在res的drawable的文件下新建一个文件,其根元素是shape,然后添加所需属性。
但我们希望UI设计能更加吸引用户的眼球,实际物体的效果(3D效果)。可以用CardView实现视觉冲击,对与卡片设计。感兴趣的可以去了解Material Design
可以查看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
使用步骤:
1、添加库依赖
compile 'com.android.support:cardview-v7:25.3.0'
2、然后在布局中直接引用
<android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="70dp" app:cardBackgroundColor="#eff229" app:cardCornerRadius="10dp" app:cardElevation="5dp" app:contentPadding="5dp"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="CardView是什么玩意" android:gravity="center_horizontal|center_vertical" android:textColor="#000000" android:textSize="25sp"/> </android.support.v7.widget.CardView>>3、手机上运行效果更加清晰:
看自己需求了,当然我们也要与时俱进去了解、学习。