Android SeekBar Flipped Horizontally

匿名 (未验证) 提交于 2019-12-03 01:48:02

问题:

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!

回答1:

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. How can you display upside down text with a textview in Android?
  2. How can I get a working vertical SeekBar in Android?


回答2:

Have you tried seekbar.setRotation( 180 )? It flips the seekbar 180 degrees and is upside down, meaning left side is max, right side is 0 with the color on the right of the thumb. No need to create a custom seekbar this way.



回答3:

You should look into making a custom progress bar. Considering what you want to do, you already have the images you need in the Android SDK. I'd extract them and edit them accordingly. Here's a tutorial to help get you started.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!