【Android】ProgressBar进度是圆角模型写法

在xml布局中声明ProgressBar:

<ProgressBar
            android:id="@+id/progress"
            android:layout_width="match_parent"
            android:layout_height="@dimen/x16"
            android:layout_marginLeft="@dimen/x30"
            android:layout_marginRight="@dimen/x30"
            style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
            android:layout_below="@id/progress_tv"
            android:layout_marginTop="@dimen/x12"
            android:layout_marginBottom="@dimen/x50"
            android:max="100"
            android:progress="50"
            android:progressDrawable="@drawable/property_star_progress"
            />

property_star_progress.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="@dimen/x21" />
            <solid android:color="#eaeaea"/>
        </shape>
    </item>

    <item android:id="@android:id/progress">
        <!--不能使用clip,clip会将progress的右边裁成直角,必须使用scale-->
        <!--<clip>
            <shape>
                <corners
                    android:radius="@dimen/x21"/>
                <gradient
                    android:angle="0"
                    android:startColor="#5a5df6"
                    android:endColor="#3f6ef6"/>
            </shape>
        </clip>-->
        <scale
            android:scaleWidth="100%"
            android:drawable="@drawable/property_star_progress_scale"/>
            <!--android:scaleWidth="50%"-->
            <!--android:drawable="@drawable/property_star_progress_scale"  bg_wuyezhixing-->
    </item>

</layer-list>

scale标签是定义一个scaleDrawable图形对象,scaleWidth是设置引用的图片资源显示时是否要缩放(百分比),100%不缩放。详情见:ScaleDrawable

其中,property_star_progress_scale.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <corners
        android:radius="@dimen/x21"/>
    <gradient
        android:angle="0"
        android:startColor="#5a5df6"
        android:endColor="#3f6ef6"/>

</shape>

效果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值