Android 镜像(翻转)视图/进度条
我有一个定制的圆形进度条,用于时钟上的秒计数器,我想翻转它,这样时钟就会逆时针计数 在此处搜索解决方案时,我发现: 这显然适用于水平进度条,但我不能简单地将其旋转180度,因为这只会将时钟移动180度,它仍然会顺时针滴答作响 是否有其他方法镜像ProgressBar或任何视图 编辑:Android 镜像(翻转)视图/进度条,android,android-widget,android-progressbar,material-components-android,progress-indicator,Android,Android Widget,Android Progressbar,Material Components Android,Progress Indicator,我有一个定制的圆形进度条,用于时钟上的秒计数器,我想翻转它,这样时钟就会逆时针计数 在此处搜索解决方案时,我发现: 这显然适用于水平进度条,但我不能简单地将其旋转180度,因为这只会将时钟移动180度,它仍然会顺时针滴答作响 是否有其他方法镜像ProgressBar或任何视图 编辑: 刚刚找到了“android:rotationY”和编程等效程序,但理想情况下,它需要适用于2.2及以上版本。以与水平进度条相同的方式扩展进度条,但在onDraw方法中,翻转画布而不是旋转它: public cla
刚刚找到了“android:rotationY”和编程等效程序,但理想情况下,它需要适用于2.2及以上版本。以与水平进度条相同的方式扩展进度条,但在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);
}
}
我可以简单地用XML中的属性
scaleX
翻转ProgressBar
:
android:scaleX="-1"
这也适用于其他视图。是。在的较新版本中,可以镜像圆形进度条:
- 在具有此属性的布局中
app:indicatorDirectionCircular
- 或以编程方式使用此方法
setIndicatorDirection()
请参阅更多信息。这不是一个真正的答案,但是你会考虑开放式循环进度条吗?我看到很多人要求它。这是我最初的做法:但从那时起,它发生了很多变化。假期过后,我可以在github上创建一个示例应用程序!这回答了你的问题吗?