【问题标题】:How can I do that circular countdown go with the clockwise?我怎样才能按照顺时针方向进行循环倒计时?
【发布时间】:2017-02-04 20:55:12
【问题描述】:

我有一个倒计时的圆形进度条。倒计时从圆形进度条的顶部开始,这很好,但要向左进行倒计时。我想要的是倒计时的旋转向右,就像顺时针一样。

我的circle_progress_foreground.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@android:id/progress">
        <shape
            android:innerRadiusRatio="3"
            android:shape="ring"
            android:thicknessRatio="30"
            android:useLevel="true">

            <gradient
                android:startColor="@color/circle_progress_two"
                android:endColor="@color/circle_progress"
                android:type="sweep" />
        </shape>
    </item>
</layer-list>

我的布局中的进度条

<ProgressBar
            android:id="@+id/progressbar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="280dip"
            android:layout_height="290dip"
            android:indeterminate="false"
            android:progressDrawable="@drawable/circle_progress_foreground"
            android:background="@drawable/circle_shape"
            android:max="100"
            android:rotation="-90"
            android:layout_alignParentTop="true"
            android:layout_alignLeft="@+id/progressBar"
            android:layout_alignStart="@+id/progressBar"
            android:layout_centerHorizontal="false"
            android:layout_centerInParent="false"
            android:layout_centerVertical="false" />

我班上的代码:

mProgressBar = (ProgressBar) findViewById(R.id.progressbar);

【问题讨论】:

标签: android android-progressbar


【解决方案1】:

试试这个方法来设置你的旋转

circle_progress_foreground.xml

 <?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="270"
    android:toDegrees="270">
    <shape
        android:innerRadiusRatio="2.5"
        android:shape="ring"
        android:thickness="1dp"
        android:useLevel="true">

        <gradient
            android:angle="0"
            android:endColor="#007DD6"
            android:startColor="#007DD6"
            android:type="sweep"
            android:useLevel="false" />
    </shape>
</rotate>

圆形形状

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:innerRadiusRatio="2.5"
    android:thickness="1dp"
    android:useLevel="false">

    <solid android:color="#CCC" />

</shape>

进度条

<ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:indeterminate="false"
        android:progressDrawable="@drawable/circle_progress_foreground"
        android:background="@drawable/circle_shape"
        style="?android:attr/progressBarStyleHorizontal"
        android:max="100"
        android:progress="65" />

【讨论】:

  • 仍在以与顺时针相反的方式进行旋转。我希望它以与顺时针相同的方式旋转
  • 我知道你什么?
  • 嗨。如果使用您的代码,但开始倒计时时不是顺时针方向。从右向左旋转,我希望以与顺时针相同的方式从右向左旋转。现在我得到相反的旋转。
  • 是的,我尝试过编辑答案和顺时针方向的相反
  • 我已经用这个 我去接受你的回答。如果您可以编辑并添加对我有用的正确值,那将是完美的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-18
  • 2013-08-18
  • 2019-07-13
  • 2014-05-14
  • 1970-01-01
  • 2020-08-14
  • 2012-02-27
相关资源
最近更新 更多