Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I make off-center rotate animations in android look similar in portrait and landscape?
    primarykey
    data
    text
    <p>I have a screen that has a few images and one of them has a neat animation on it that looks awesome in portrait.</p> <p>Awesome animation in portrait - rotate_anim_port.png - in <a href="http://nicedice.scdevtesting.com/anim/" rel="nofollow">HERE</a></p> <p>It does not look so awesome in landscape. </p> <p>Animation in landscape - rotate_anim_land.png - in above.</p> <p>I am implementing the off-center rotation animation in this way because I have several imageviews with drawable resources of the same size stacked together in a frameview to keep them all in relatively the same spot, but able to scale to whatever size the frameview is.</p> <p>It looks bad because the view in which the <code>RotateAnimation(fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue)</code> is basing its pivotValues off of is not the same size as the image inside the view. When in portrait, the image is virtually the same size as the view, but in landscape the difference is apparent.</p> <p>I have been trying and failing to get the positions from both the view and the drawn image inside of it to use to math up the proper pivotValues to pass in code.</p> <p>Here is the code for the activity:</p> <pre><code>package com.namespace; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.view.animation.Animation; import android.view.animation.LinearInterpolator; import android.view.animation.RotateAnimation; import android.widget.ImageView; public class AnimationDemoActivity extends Activity { // piviotValues if the view is the exact size of the drawable. final float pivotXType = 0.3280274656679151f; final float pivotYValue = 0.5060137457044674f; private Handler mHandler = new Handler(); ImageView outside, inside; RotateAnimation anim, anim2; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); outside = (ImageView) findViewById(R.id.imageView1); inside = (ImageView) findViewById(R.id.imageView2); outside.setVisibility(ImageView.INVISIBLE); inside.setVisibility(ImageView.INVISIBLE); // somewhere in here, code to recalculate pivotValues to adjust for the // size of the actual view the images are inside of anim = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, pivotXType, Animation.RELATIVE_TO_SELF, pivotYValue); anim.setInterpolator(new LinearInterpolator()); anim.setRepeatCount(Animation.INFINITE); anim.setDuration(2000); anim2 = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, pivotXType, Animation.RELATIVE_TO_SELF, pivotYValue); anim2.setInterpolator(new LinearInterpolator()); anim2.setRepeatCount(Animation.INFINITE); anim2.setDuration(750); mHandler.postDelayed(doRotation, 2500); } private Runnable doRotation = new Runnable() { public void run() { outside.setVisibility(ImageView.VISIBLE); inside.setVisibility(ImageView.VISIBLE); outside.startAnimation(anim); inside.startAnimation(anim2); } }; } </code></pre> <p>and here is the layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:orientation="vertical" android:padding="10sp" &gt; &lt;ImageSwitcher android:id="@+id/imageSwitcher1" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:gravity="center" &gt; &lt;/ImageSwitcher&gt; &lt;ImageSwitcher android:id="@+id/imageSwitcher2" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:gravity="center" &gt; &lt;/ImageSwitcher&gt; &lt;FrameLayout android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:gravity="center" &gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/dwdg_outside_arrow" &gt; &lt;/ImageView&gt; &lt;ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/dwdg_inside_arrow" &gt; &lt;/ImageView&gt; &lt;/FrameLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p><a href="http://nicedice.scdevtesting.com/anim/" rel="nofollow">Here</a> is runnable apk - AnimationDemo.apk and zipped project - AnimationDemo.zip</p> <p>Am I crazy for doing it this way? Am I totally overlooking something? What do?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload