0

我需要有关 android 动画的帮助。当应用程序启动时,我需要显示兔子从框中出现。如果有人碰了兔子,他会躲起来,然后他会再次出现。谢谢

public class Test extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);


    ImageView rabbit = (ImageView) findViewById(R.id.rabbit);

    Animation rAnimation = AnimationUtils.loadAnimation(this,
            R.animator.rabbit);
    // apply the animation to the View
    rabbit.startAnimation(rAnimation);

}
}

测试布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
 >

<ImageView
    android:id="@+id/rabbit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/rabbit"
    android:paddingLeft="100dp"
    android:paddingTop="45dp"
    android:src="@drawable/rabbit" />


<ImageView
    android:id="@+id/box"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/box"
    android:paddingLeft="200dp"
    android:paddingTop="90dp"
    android:src="@drawable/box" />


</RelativeLayout>

动画

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:duration="5000"
android:fillAfter="true"
android:interpolator="@android:anim/accelerate_decelerate_interpolator" >

<scale
android:fromXScale="1.0"
android:toXScale="1.2"
android:fromYScale="1.2"
android:toYScale="1.5"
android:pivotX="50%"
android:pivotY="50%"
/>

<translate 
    android:fromYDelta="10%p"
    android:toYDelta="0%p"
    />

<alpha
    android:fromAlpha="0.3"
    android:toAlpha="1.0"
    />

</set>
4

0 回答 0