镜像(翻转)View/ProgressBar

7 xml android android-widget

我有一个定制的圆形进度条用于时钟上的秒计数器,我想翻转,以便时钟逆时针计数.

在这里搜索解决方案,我发现了这个:

从右到左ProgressBar?

这显然适用于水平进度条,但我不能简单地将其旋转180度,因为这只会将时钟移动180度,它仍然会顺时针旋转.

有没有其他方法可以镜像ProgressBar或任何View?

编辑:

刚刚找到"android:rotationY"和程序化的等价物,但这理想情况下需要为2.2及以上..

Mic*_*cer 6

我能够ProgressBar简单地翻转scaleXXML中的属性:

android:scaleX="-1"
Run Code Online (Sandbox Code Playgroud)

这也适用于其他View人。


小智 3

以与水平进度条相同的方式扩展 ProgressBar,但在 onDraw 方法中,翻转画布而不是旋转它:

public class InverseProgressBar extends ProgressBar {

public InverseProgressBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public InverseProgressBar(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public InverseProgressBar(Context context) {
    super(context);
}

@Override
protected synchronized void onDraw(Canvas canvas) {
    canvas.scale(-1f, 1f, super.getWidth() * 0.5f, super.getHeight() * 0.5f);
    super.onDraw(canvas);
}

}
Run Code Online (Sandbox Code Playgroud)