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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章