Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to spin an android icon on its center point?

I have written the following to spin my icon on the center of the screen and instead it rotates around the upper-left corner (i.e., origin x=0, y=0 of the ImageView). It should be simple to set some attributes of the ImageView or the RotateAnimation, but I can't figure it out.

public class IconPromoActivity extends Activity {     private static final float ROTATE_FROM = 0.0f;     private static final float ROTATE_TO = -10.0f * 360.0f;// 3.141592654f * 32.0f;      /** Called when the activity is first created. */     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);          ImageView favicon = (ImageView) findViewById(R.id.favicon);          RotateAnimation r; // = new RotateAnimation(ROTATE_FROM, ROTATE_TO);         r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, 0, 0, 40, 0);         r.setDuration((long) 2*1500);         r.setRepeatCount(0);         favicon.startAnimation(r);     } } 
like image 764
mobibob Avatar asked Jun 29 '10 02:06

mobibob


People also ask

How to turn on the loading spinner in Android Studio?

Android studio installs the app on your AVD and starts it and if everything is fine with your setup and application, it will display following Emulator window − Now click on the load spinner button to turn on the loading spinner. It is shown in the image below −

How do I make a button hang to the left on Android?

android:drawableLeft is always keeping android:paddingLeft as a distance from the left border. When the button is not set to android:width="wrap_content", it will always hang to the left! With Android 4.0 (API level 14) you can use android:drawableStart attribute to place a drawable at the start of the text.

What is spinner in Java?

In this chapter we will discuss spinner. Spinner is used to display progress of those tasks whose total time of completion is unknown. In order to use that, you just need to define it in the xml like this.

What are the best icons for strings in Android?

Unicode has an extensive set of character icons that are compatible with strings in Android. If you can find an acceptable one, this is a simple solution, and it has the added bonus that it will scale with text size. For instance, it has an envelope for an email icon and a couple of different phones for a call button.


2 Answers

Try: r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

like image 169
Rich Schuler Avatar answered Sep 28 '22 01:09

Rich Schuler


This works for me:

img = (ImageView)findViewById(R.id.ImageView01); RotateAnimation rotateAnimation = new RotateAnimation(30, 90,     Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
like image 42
Rodrigo Ferreira Avatar answered Sep 28 '22 02:09

Rodrigo Ferreira