View背景渐变色(shape,gradient),shape代替图片(减小APP size)- android

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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值