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); } }
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 −
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.
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.
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.
Try: r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With