Turn the button (or text inside) in the code

I need to rotate a button (or text inside, same thing) with a random degree of coding. Is there a button.setRotate (x) in the API level lower than 11 ??

+5
source share
1 answer

Well, I looked, and the answer is: it is difficult.

You can rotate the button using the old animation environment, for example. eg:

Button button = (Button) findViewById(R.id.button);

// rotation from 0 to 90 degrees here
RotateAnimation a = new RotateAnimation(0, 90);
a.setFillAfter(true);
a.setDuration(0);
button.startAnimation(a);

The problem is that the button looks to rotate, but it cannot be clicked correctly. The coordinates that trigger the click event are those areas in which the button was before the rotation.

, , Button onDraw(). onMeasure(). . , .

, , . "".

+4

All Articles