android 自定义控件——(四)圆形进度条

----------------------------------↓↓圆形进度条(源代码下有属性解释)↓↓-----------------------------------------------------

 

 

 

一、shape 样式:(在drawable新建--》new--》Drawable resource file 并把原父级标签selector改为shape

 
    
<?xml version="1.0" encoding="utf-8"?>
<!--把shape嵌套在rotate里面实现环形旋转-->
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="1080.0"
>
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="9"
android:useLevel="false">
<gradient
android:startColor="#ffffff"
android:endColor="#4ec5ff"
android:type="sweep" />
</shape>
</rotate>

二、style 样式:
<style name="ring">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:indeterminateDrawable">@drawable/buttonringstyle</item>
</style>

三、Button控件调用style样式:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ly.blogtest.MainActivity">
<ProgressBar
style="@style/ring"
android:id="@+id/progressBar"
/>
 
    
</RelativeLayout>

----------------------------------↑↑↑↑圆形进度条↑↑↑↑↑-----------------------------------------------------

 

----------------------------------↓↓↓android:shape属性指定形状↓↓↓------------------------------

  • rectangle: 矩形,默认的形状,可以画出直角矩形、圆角矩形、弧形等
  • oval: 椭圆形,用得比较多的是画正圆
  • line: 线形,可以画实线和虚线
  • ring: 环形,可以画环形进度条

----------------------------------↑↑↑android:shape属性指定形状↑↑↑------------------------------

 

----------------------------------↓↓↓只适用于ring的特殊属性↓↓----------------------------------

  注:shape中有一些特殊属性只适用于ring:

  • android:innerRadius 内环的半径
  • android:innerRadiusRatio 浮点型,以环的宽度比率来表示内环的半径,默认为3,表示内环半径为环的宽度除以3,该值会被android:innerRadius覆盖
  • android:thickness 环的厚度
  • android:thicknessRatio 浮点型,以环的宽度比率来表示环的厚度,默认为9,表示环的厚度为环的宽度除以9,该值会被android:thickness覆盖
  • android:useLevel 一般为false,否则可能环形无法显示,只有作为LevelListDrawable使用时才设为true

----------------------------------↑↑↑只适用于ring的特殊属性↑↑↑----------------------------------

 

----------------------------------↓↓shape的属性标签↓↓-----------------------------------------

  <shape>
            <!-- 实心 -->
            <solid android:color="#ff9d77"/>
            <!-- 渐变 -->
            <gradient
                android:startColor="#ff8c00"
                android:endColor="#FFFFFF"
                android:angle="270" />
            <!-- 描边 -->
            <stroke
                android:width="2dp"
                android:color="#dcdcdc" />
            <!-- 圆角 -->
            <corners
                android:radius="2dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>

 

 

 

  • solid: 设置形状填充的颜色,只有android:color一个属性

    • android:color 填充的颜色
  • padding: 设置内容与形状边界的内间距,可分别设置左右上下的距离

    • android:left 左内间距
    • android:right 右内间距
    • android:top 上内间距
    • android:bottom 下内间距
  • gradient: 设置形状的渐变颜色,可以是线性渐变、辐射渐变、扫描性渐变

    • android:type 渐变的类型
      • linear 线性渐变,默认的渐变类型
      • radial 放射渐变,设置该项时,android:gradientRadius也必须设置
      • sweep 扫描性渐变
    • android:startColor 渐变开始的颜色
    • android:endColor 渐变结束的颜色
    • android:centerColor 渐变中间的颜色
    • android:angle 渐变的角度,线性渐变时才有效,必须是45的倍数,0表示从左到右,90表示从下到上
    • android:centerX 渐变中心的相对X坐标,放射渐变时才有效,在0.0到1.0之间,默认为0.5,表示在正中间
    • android:centerY 渐变中心的相对X坐标,放射渐变时才有效,在0.0到1.0之间,默认为0.5,表示在正中间
    • android:gradientRadius 渐变的半径,只有渐变类型为radial时才使用
    • android:useLevel 如果为true,则可在LevelListDrawable中使用
  • corners: 设置圆角,只适用于rectangle类型,可分别设置四个角不同半径的圆角,当设置的圆角半径很大时,比如200dp,就可变成弧形边了

    • android:radius 圆角半径,会被下面每个特定的圆角属性重写
    • android:topLeftRadius 左上角的半径
    • android:topRightRadius 右上角的半径
    • android:bottomLeftRadius 左下角的半径
    • android:bottomRightRadius 右下角的半径
  • stroke: 设置描边,可描成实线或虚线。

    • android:color 描边的颜色
    • android:width 描边的宽度
    • android:dashWidth 设置虚线时的横线长度
    • android:dashGap 设置虚线时的横线之间的距离

 

----------------------------------↑↑shape的属性标签↑↑-----------------------------------------

posted on 2016-10-31 17:00 "茶树" 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/LOVEJIEYING/p/6016495.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值