【问题标题】:Mirror (flip) a View / ProgressBar镜像(翻转)视图/进度条
【发布时间】:2012-12-10 22:22:08
【问题描述】:

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

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

Right to Left ProgressBar?

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

还有其他方法可以镜像 ProgressBar 或任何视图吗?

编辑:

刚刚找到“android:rotationY”和程序等效项,但理想情况下这需要用于 2.2 及更高版本..

【问题讨论】:

标签: android android-widget android-progressbar material-components-android progress-indicator


【解决方案1】:

我可以简单地使用 XML 中的属性 scaleX 翻转 ProgressBar

android:scaleX="-1"

这也适用于其他View

【讨论】:

    【解决方案2】:

    以与水平进度条相同的方式扩展 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);
    }
    
    }
    

    【讨论】:

      【解决方案3】:

      是的。在较新版本的material design library 中,可以镜像圆形进度条:

      • 在具有此属性的布局中
        app:indicatorDirectionCircular
        
      • 或以编程方式使用此方法
        setIndicatorDirection()
        

      更多信息请参考here

      【讨论】:

        猜你喜欢
        • 2012-01-14
        • 2017-06-24
        • 2023-03-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-28
        • 1970-01-01
        相关资源
        最近更新 更多