2. android补间动画

目录结构

 

 

2. android补间动画_第1张图片

第一步

anim/tween_anim.xml

 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="6000"/> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="9000"/> <translate android:fromXDelta="30" android:toXDelta="0" android:fromYDelta="30" android:toYDelta="0" android:duration="10000"/> <rotate android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromDegrees="0" android:toDegrees="+360" android:pivotX="50%" android:pivotY="50%" android:duration="10000"/> </set>

第二步

layout/tween_anim.xml

 

 <?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"> <ImageView android:id="@+id/iv" android:src="@drawable/p1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" /> <Button android:id="@+id/btn" android:text="Click" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>

第三步

TweenAnimActivity.java

 

 package com.skytao; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageView; public class TweenAnimActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tween_anim); Button btn = (Button) findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ImageView iv = (ImageView) findViewById(R.id.iv); Animation animation = AnimationUtils.loadAnimation(TweenAnimActivity.this, R.anim.tween_ani); iv.startAnimation(animation); } }); } }

你可能感兴趣的:(2. android补间动画)