Progressbar覆盖不全是圆角的问题

这里遇到一个就是自定义水平进度条样式的问题,就是覆盖在上层的进度不能显示圆角。
这里写图片描述
我们想要实现的效果是如下图的样子的。后来发现原因就是我们用了用了clip属性来切割图片,被clip切了所以变成了直角,所以我们不用clip标签改为scale这个标签就完美解决了。实现效果如下图:
这里写图片描述

1.xml中的引用:

 <ProgressBar
            android:id="@+id/progress_count"
            style="@style/mProgress_horizontal"
            android:layout_width="match_parent"
            android:layout_height="36px"
            android:layout_marginLeft="35px"
            android:layout_marginRight="35px"
            android:layout_marginTop="36px"
            android:progress="0"
            android:secondaryProgress="50" />

2.style中的代码:

 <!--自定义水平进度条-->
    <style name="mProgress_horizontal">
        <item name="android:indeterminateOnly">false</item>
        <item name="android:progressDrawable">@drawable/progressbar_horizontal
        </item><!-- progress_horizontal -->
        <item name="android:indeterminateDrawable">
            @android:drawable/progress_indeterminate_horizontal
        </item>
    </style>

3.关键就是这个android:progressDrawable的属性了,progressbar_horizontal的代码

<?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="50dip" />
            <gradient
                android:angle="270"
                android:centerColor="@color/progressbg"
                android:centerY="0.75"
                android:endColor="@color/progressbg"
                android:startColor="@color/progressbg" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <scale android:scaleWidth="100%">
            <shape>
                <corners android:radius="50dip" />
                <gradient
                    android:angle="270"
                    android:centerY="0.75"
                    android:endColor="@color/textorange"
                    android:startColor="@color/orange" />
            </shape>
        </scale>
    </item>

    <item android:id="@android:id/progress">
        <scale android:scaleWidth="100%">
            <shape>
                <corners android:radius="50dip" />
                <gradient
                    android:angle="270"
                    android:centerY="0.75"
                    android:endColor="@color/textorange"
                    android:startColor="@color/orange" />
            </shape>
        </scale>
    </item>


</layer-list>
可以看到的是我们只是吧<clip/>标签内容替换为<scale android:scaleWidth="100%">就可以了。或许.9图也是可以实现的,scale标签顾名思义就是拉伸的意思。。。不会切割。

总结:开心,开心就好。。。

发布了89 篇原创文章 · 获赞 141 · 访问量 24万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章