Right to Left ProgressBar?

2019-01-14 16:25发布

Does anyone know how to make a View reversed, I have a horizontal ProgressBar and I want it to right to left instead of left to right

8条回答
何必那么认真
2楼-- · 2019-01-14 17:07

It's even easier. You can simply call the following method and then it's rotated and works just how you wanted.

progressBar.setRotation(180);

An example: a normal progressbar and a RTL progressbar

查看更多
Evening l夕情丶
3楼-- · 2019-01-14 17:14
 public class inverseSeekBar extends ProgressBar {

public inverseSeekBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    // TODO Auto-generated constructor stub
}

public inverseSeekBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}

public inverseSeekBar(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}

@Override
protected synchronized void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
     canvas.save(); 

        //now we change the matrix
        //We need to rotate around the center of our text
        //Otherwise it rotates around the origin, and that's bad. 
        float py = this.getHeight()/2.0f;
        float px = this.getWidth()/2.0f;
        canvas.rotate(180, px, py); 

        //draw the text with the matrix applied. 
        super.onDraw(canvas); 

        //restore the old matrix. 
        canvas.restore(); 
}}
  <com.hlidskialf.android.widget.inverseSeekBar 

       style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="200dip"
    android:layout_height="wrap_content"
    android:max="100"
    android:progress="50"
    android:secondaryProgress="75" 

/> 

mypackage: com.test.testProgressBar

查看更多
登录 后发表回答