views:

272

answers:

1

How to rotate control (checkbox) in 180 or 90 degrees ?

+2  A: 

One way is roughly the same as in this question:

public class CheckBox90 extends CheckBox {
    public CheckBox90(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.rotate(90,20,20);
        super.onDraw(canvas);
    }
}

...but that's kind of hacky. Probably better to do it this way. Grab the checkbox images, rotate them in the image editor of your choice, then tell Android to use the rotated versions.

Daniel
thanks man , great ;)
How to call in main program (what to type in main.xml) ?
http://developer.android.com/guide/topics/ui/custom-components.html#modifying
Daniel
thanks, thanks, thanks... :) I don't have much points to vote for the your post :)
I'd argue that the hacky way you described is actually better than creating new images - that way, if the whole has a different look and feel and custom checkbox images, the app will use those instead of rotated versions of the standard Android checkboxes. And user346665 - you should be able to mark Daniel's post as the "best answer".
EboMike
The problem with the hacky way is that I had to play around to figure out which pivot point offset to use - in this case, (20, 20). If the GUI element size changes, those numbers will probably have to change - which is bad. I'm not sure if there's a way to programmatically determine what pivot point to use, as I didn't spend that time researching it, but there may be.
Daniel