I am new to android development, can any one tell me how to rotate entire a button into 45 degrees along with text and button rect. I want to rotate permanently and i want on click listener on the same.
Asked
Active
Viewed 1,744 times
3
-
1Make your question more clear. Whether you want to rotate the button permanently and on what event(like on button click etc).. – Dinesh Sharma Nov 08 '11 at 10:03
-
There's a related question (where you will find your answer) here: http://stackoverflow.com/questions/1930963/rotating-a-view-in-android – Yevgeny Simkin Nov 08 '11 at 10:04
-
@Dinesh I want to rotate permanently and i want on click listener on the same. – AndroidDev Nov 08 '11 at 10:06
1 Answers
0
You need to use animations for that.
in your /res/anim/ you must create an xml file with this:
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:duration="0"
android:startOffset="0"
/>
and the in your Activity:
RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.YOUR_ANIM);
ranim.setFillAfter(true);
YourButton.setAnimation(ranim);
Apart from that it seems that there are some problems with diagonal rotations (a.k.a. 45 degrees) pre-honeycomb..

SERPRO
- 10,015
- 8
- 46
- 63
-
Are you sure that the Rotation animation will rotate the actual view rectangle. – AndroidDev Nov 08 '11 at 10:10
-
Well I used it on my own app.. you can see an screenshot here.. https://ssl.gstatic.com/android/market/appinventor.ai_serpro.MTGDroid/ss-800-1-14 the buttons to add and subtract are the same but rotated. also the same with the horizontal ones. – SERPRO Nov 08 '11 at 10:13
-
I tried this but on click listener on the rotated button is not working. – AndroidDev Nov 08 '11 at 10:18
-
I saw that problem yesterday in SO. The problem was that the OnClickListener worked on the top part, but not on the bottom.. and they found out that it's a pre-honeycomb problem.. is that your problem too? – SERPRO Nov 08 '11 at 10:35
-
Yes mine also OnClickListener is working only in the top part. how to resolve this problem...? – AndroidDev Nov 08 '11 at 10:39
-