安卓自定义圆形进度条方向

9

我有一个自定义的圆形进度条。这是我用来确定它的可绘制对象:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@android:id/secondaryProgress">
    <shape
        android:innerRadiusRatio="6"
        android:shape="ring"
        android:thicknessRatio="20.0"
        android:useLevel="true">
     <gradient
          android:centerColor="#999999"
          android:endColor="#999999"
          android:startColor="#999999"
          android:type="sweep" />
    </shape>
  </item>
  <item android:id="@android:id/progress">
   <rotate
      android:fromDegrees="270"
      android:pivotX="50%"
      android:pivotY="50%"
      android:toDegrees="270">

  <shape
      android:innerRadiusRatio="6"
      android:shape="ring"
      android:thicknessRatio="20.0"
      android:useLevel="true">


    <rotate
        android:fromDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="0" />

    <gradient
        android:centerColor="?attr/colorAccent"
        android:endColor="?attr/colorAccent"
        android:startColor="?attr/colorAccent"
        android:type="sweep" />

      </shape>
    </rotate>
  </item>
</layer-list>

我希望它以顺时针方向显示进度,但现在它显示为逆时针。

我该如何更改?


你是如何增加进度的?我有一个圆形进度条,使用了你的可绘制对象,并且它顺时针旋转。 - khusrav
5个回答

20

我猜你正在使用一种从右往左的语言?你可以通过在 ProgressBar 上设置 layoutDirection 属性来强制进度条为从左往右或顺时针方向。

<ProgressBar
    ...
    android:layoutDirection="ltr" />

2

通过使用最新版本的Material Design库, 您可以实现以下效果:

  • in the layout with this attribute
    app:indicatorDirectionCircular
    
  • or programmatically with this method
    setIndicatorDirection()
    

请参考这里获取更多信息。


0

更改这个

<rotate
    android:fromDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="0" />

<rotate
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" />

不起作用。一开始就是这样,我试着改变了它。 - amitairos

0

我不确定它是否有效,但是尝试设置android:toDegrees="-360"像这样:

<rotate
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="-360" />

0
你可以通过180度改变Y轴的旋转。
android:rotationY="180"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接