您的位置:首页 > 其它

竖直ProgressBar(VerticalProgressBar),不用那么麻烦

2016-07-04 16:20 1361 查看
之前一直通过把横向ProgressBar(设置了progressBarStyleHoriziontal)宽高互换的方式来自定义一个VerticalProgressBar实现竖直方向的ProgressBar。但是却发现一个bug,就是竖直方向的时候,如果设置宽度大于高度,显示出来的竖直ProgressBar宽度可能只显示出来一半。然后就是查资料了,但是百度和Google看下来,基本没有人遇到这个问题。后来看到大神总结的ProgressBar深入分析,仔细看完,豁然开朗,立刻解决了困扰自己的难题,以后再遇到这类问题,把相关控件属性看一遍,可能会有意想不到的作用。

android:indeterminateOnly

限制ProgressBar只能使用模糊模式。

true

限制只能使用模糊模式。

false

不限制只能使用模糊模式。

通过设置这个属性,再自定义progressDrawable,就可以实现竖直的ProgressBar。

以下是一个例子:



res/layout/activity_main.xml


<ProgressBar
android:id="@+id/pb_vertical_simple_shape"
android:layout_width="20dp"
android:layout_height="150dp"
android:layout_margin="20dp"
android:indeterminateOnly="false"
android:max="100"
android:progress="70"
android:progressDrawable="@drawable/progress_vertical_gradient_simple_shape" />


res/drawable/progress_vertical_gradient_simple_shape.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="5dip" />
<gradient
android:angle="270"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:startColor="#ff9d9e9d" />
</shape>
</item>

<item android:id="@android:id/secondaryProgress">
<clip
android:clipOrientation="vertical"
android:gravity="bottom">
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="90"
android:endColor="#a0ffcb00"
android:startColor="#80ffd300" />
</shape>
</clip>
</item>

<item android:id="@android:id/progress">
<!-- 定义ClipDrawable的剪裁方向为垂直 -->
<clip
android:clipOrientation="vertical"
android:gravity="bottom">
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="90"
android:endColor="#ffff4b00"
android:startColor="#ffffd300" />
</shape>
</clip>
</item>

</layer-list>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  竖直Progress