ProgressBar自定义旋转Drawable and shape相关属性

本文介绍了如何自定义ProgressBar的旋转Drawable,并详细讲解了Shape的各种图形类型及其常用属性,包括solid、corners、padding、stroke、gradient等,帮助读者深入理解Shape在Android开发中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自定义rotate

android:toDegrees值可以改变旋转的速度

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="1080"> 

    <shape
        android:shape="ring"
        android:thickness="3px"
        android:useLevel="false">
        <gradient
            android:centerColor="@color/colorbbbbbb"
            android:centerY="0.50"
            android:type="linear"
            android:angle="-135"
            android:endColor="@color/colorffffff"
            android:centerX="0.5"
            android:startColor="@color/colorbbbbbb"
            android:useLevel="false" />

    </shape>
</rotate>

shape图形类型

关于Shape的使用,简单来说说吧,
shape作为Android程序员你也是一定会用到的一个工具。
用官方的话来说,这是在 XML 中定义的一般形状。指向 GradientDrawable 的资源指针。
Shape可以绘制几种图形:

  • 方型:rectangle,这也是默认的形状
  • 原型:oval
  • 线性:line
  • 环:ring,为环的时候还有些针对它才使用的一些属性
我们用到的属性

solid :用于填充形状的纯色 corners:为形状产生圆角。仅当形状为矩形时适用

android:radius : 所有角都进行圆角处理半径,如果有单独设置某个角,这个属性则会被覆盖
android:topLeftRadius : 左上圆角 android:topRightRadius : 右上圆角
android:bottomLeftRadius : 左下圆角 android:bottomRightRadius : 右下圆角

padding : 要应用到包含视图元素的内边距(这会填充视图内容的位置如textview那么就是和文字都内编剧距离,而非形状)

android:left : 左内边距 android:top : 上内边距 android:right :右内边距
android:bottom :下内边距

size :
形状的大小,可以通过这里来设置形状大小,默认根据这里设置的大小来等比缩放至容器大小。在ImageView中可设置android:scaleType
设置为 “center” 来限制缩放。 stroke : 描边,就是最外面一层边线,可以是实线也可以是虚线

android:width :线宽 android:color :颜色 android:dashWidth :虚线的间距。仅在设置了
android:dashGap 时有效 android:dashGap : 虚线的厚度大小。仅在设置了 android:dashWidth 时有效

gradient :形状渐变颜色。

android:angle : 整型。渐变的角度(度)。0 为从左到右,90 为从下到上,270 从上到下。必须是 45 的倍数。默认值为 0
android:centerX : 浮点型。渐变中心的相对 X 轴位置 (0 - 1.0)。 android:centerY :
浮点型。渐变中心的相对 Y 轴位置 (0 - 1.0)。
android:centerColor :颜色。起始颜色与结束颜色之间的可选颜色
android:endColor : 颜色。结束颜色
android:gradientRadius : 浮点型。渐变的半径。仅在
android:type=“radial” 时适用。
android:startColor : 颜色。起始颜色
android:type :要应用的渐变图案的类型linear :线性渐变。这是默认值 radial : 径向渐变。起始颜色为中心颜色。 sweep : 流线型渐变。
android:useLevel [“true” | “false”] 如果要使用LevelListDrawable对象,就要设置为true。设置为true无渐变。false有渐变色默认为true (要看效果还是建议设为false,属性还没摸透)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值