這裏遇到一個就是自定義水平進度條樣式的問題,就是覆蓋在上層的進度不能顯示圓角。
我們想要實現的效果是如下圖的樣子的。後來發現原因就是我們用了用了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標籤顧名思義就是拉伸的意思。。。不會切割。
總結:開心,開心就好。。。