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
+2
A:
Make a subclass of the normal progress bar view and implement the onDraw method to rotate the cnavas before drawing it:
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.rotate(180,<CenterX>,<CenterY>);
super.onDraw(canvas);
canvas.restore();
}
This should do the trick.
Moss
2010-10-07 10:06:36
A:
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
pengwang
2010-10-07 12:47:08