Android SeekBar水平翻转 [英] Android SeekBar Flipped Horizontally

查看:489
本文介绍了Android SeekBar水平翻转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Android SeekBar,通常可以将拇指向左或向右拖动,黄色进度色在拇指的左侧.我想要完全相反的方法,本质上是将黄色进度色翻转到拇指的右侧,并在y轴上翻转整个SeekBar.

With the Android SeekBar, you can normally drag the thumb to the left or to the right and the yellow progress color is to the left of the thumb. I want the exact opposite, essentially flipping the yellow progress color to the right of the thumb and flipping the entire SeekBar on the y-axis.

有人能指出我正确的方向吗?谢谢!

Can anyone point me in the right direction? Thanks!

推荐答案

在弄懂一些代码之后,这就是我所得到的,并且看起来工作得很好.希望它将对将来的其他人有所帮助.

After fiddling around with some code this is what I got and it seems to work pretty well. Hopefully it will help someone else in the future.

public class ReversedSeekBar extends SeekBar {

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

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

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

    @Override
    protected void onDraw(Canvas canvas) {
        float px = this.getWidth() / 2.0f;
        float py = this.getHeight() / 2.0f;

        canvas.scale(-1, 1, px, py);

        super.onDraw(canvas);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        event.setLocation(this.getWidth() - event.getX(), event.getY());

        return super.onTouchEvent(event);
    }
}


这是在以下两个问题的帮助下抛出的:


This was thrown together with the help of these two questions:

  1. 如何显示上方Android中具有textview的文本?
  2. 如何在Android中获得可用的垂直SeekBar?
  1. How can you display upside down text with a textview in Android?
  2. How can I get a working vertical SeekBar in Android?

这篇关于Android SeekBar水平翻转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆