如何在Android上创建动画,一张图片出现在另一张图片后面?

时间:2013-05-03 20:21:10

标签: android android-animation

我需要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>

0 个答案:

没有答案