Ron Gross
Ron Gross

Reputation: 1624

android rotating animation

i have a layout that looks like this: (without the arrows)

layout

the pictures of the animals around the layout. i want to make a rotating animation so that all the animals will go to to the direction of the arrows (actually, they should be able to rotate 360 around the view) and replace each other's location. BUT keep their own orientation - so that every animal will keep standing on her legs, and not her head :-)

I'm stuck with this problem for 2 days now, and i have no idea how to implement this

please any help? Thank you, Ron

Upvotes: 3

Views: 7653

Answers (1)

Kevin Galligan
Kevin Galligan

Reputation: 17282

You could manually animate them, like game sprites. Another option would be opposing rotate animations:

rotate_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
            android:toDegrees="0"
            android:fromDegrees="359"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="2000"
            android:repeatCount="infinite"
            android:interpolator="@android:anim/linear_interpolator"
            />
</set>

rotate_right.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
            android:toDegrees="359"
            android:fromDegrees="0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="2000"
            android:repeatCount="infinite"
            android:interpolator="@anim/lin"
            />
</set>

Layout xml file (just a text box on top and bottom. You'll have to implement the 4 corners yourself ;)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        android:orientation="horizontal">
    <FrameLayout
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:id="@+id/outer"
            >
        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:gravity="center">
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:id="@+id/top"
                    android:text="Top"/>
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:id="@+id/bottom"
                    android:text="Bottom"/>


        </LinearLayout>

    </FrameLayout>

</LinearLayout>

In your Activity:

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.[yourlayout]);

    findViewById(R.id.outer).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_left));
    findViewById(R.id.top).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_right));
    findViewById(R.id.bottom).startAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate_right));
}

For some reason I can't get the rotate to use the linear interpolator properly. It keeps speeding up/slowing down. Might have to do that in code.

Upvotes: 12

Related Questions