shape代替图片,减小APP size。
-- 用 Xml 写 Shape Drawable 太繁琐了- https://www.jianshu.com/p/8b06619ce734
Drawable drawable = new DrawableBuilder()
.line()
.build();
tvName.setBackground(drawable);
new DrawableBuilder()
.line()
.roundCorner()
.build();
new DrawableBuilder()
.line()
.roundCorner()
.fill("#d35400")
.build();
> View背景渐变色(shape,gradient)
shape是用来定义形状的,gradient定义该形状里面为渐变色填充,startColor起始颜色,endColor结束颜色,angle表示方向角度。
Android 颜色渐变(gradient),angle=0从左到右,angle=90从上到下,gradient_video_title.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="#cc000000"
android:startColor="#00000000"
android:type="linear" />
</shape>
<LinearLayout
android:background="@drawable/gradient_video_title"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
type:渐变类型:(linear表示线性渐变;sweep表示雷达渐变)
gradient属性就是用来设置渐变效果的,startColor就是最开始的颜色,centerClor就是中间的颜色,endColor就是结束的颜色,type是
设置线性渐变即竖着渐变或者横着渐变,还可以设置其他的。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:startColor="#333333"
android:centerColor="#AAAAAA"
android:endColor="#EEEEEE"
android:type="linear"/>
</shape>
日常案例的练手代码仓库- https://github.com/qingmei2/Samples-Android
> shape代替图片,减小APP size;shape绘制:矩形;椭圆;线;环;用shape绘制SeekBar
Android利用shape实现各种简单的形状- https://www.jb51.net/article/114790.htm
android之shape做图片- https://blog.csdn.net/gsw333/article/details/51851996
Android自定义图形-Shape的使用- https://blog.csdn.net/qq_27888241/article/details/77165246
Android使用shape绘制各种形状- https://blog.csdn.net/weixin_39654467/article/details/81877928
Android自定义图形-Shape- https://blog.csdn.net/u011822517/article/details/78890426
Android XML shape 标签的使用- https://www.2cto.com/kf/201807/760103.html
-- Shape实现圆形图片
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false" >
<solid android:color="@color/common_red" />
<padding
android:left="2dp"
android:top="1dp"
android:right="2dp"
android:bottom="1dp" />
<solid
android:color="@color/common_red" />
<stroke
android:width="1dp"
android:color="@android:color/white" />
<!--这里宽高要一样 -->
<size android:width="15dp"
android:height="15dp" />
</shape>