android动画实现-Tween animation(三)

来源:互联网 发布:python six.iteritems 编辑:程序博客网 时间:2024/05/18 15:09

第一步:创建动画文件在res/anim下

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="true" >
    <scale
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="1.0"
        android:toXScale="1.4"
        android:fromYScale="1.0"
        android:toYScale="0.6"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false"
        android:duration="700" />
    <set
        android:interpolator="@android:anim/accelerate_interpolator"
        android:startOffset="700" >
        <scale
            android:fromXScale="1.4"
            android:toXScale="0.0"
            android:fromYScale="0.6"
            android:toYScale="0.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="400" />
        <rotate
            android:fromDegrees="0"
            android:toDegrees="-45"
            android:toYScale="0.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="400" />
    </set>
</set>

第二步:布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<ImageView
 android:id="@+id/im"
 android:src="@drawable/aa1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
</LinearLayout>

 

第三步:测试

public class AnimationTestActivity extends Activity {
    private ImageView im=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ImageView image = (ImageView) findViewById(R.id.im);
        Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.animation_1);
        image.startAnimation(hyperspaceJump);
    }
}

原创粉丝点击