还算简单,先发个图看看效果。
主文件:
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.animation.AnimationUtils;
- import android.widget.ViewFlipper;
- public class TextAnimationActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- ViewFlipper viewFilpper = (ViewFlipper) findViewById(R.id.flipper);
- viewFilpper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_in));
- viewFilpper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_out));
- viewFilpper.startFlipping();
- }
- }
anim文件:
push_in.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <translate android:fromYDelta="100"
- android:toYDelta="0"
- android:duration="3000"/>
- <alpha android:fromAlpha="0.0"
- android:toAlpha="1.0"
- android:duration="3000" />
- </set>
push_out.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <translate android:fromYDelta="0"
- android:toYDelta="-100"
- android:duration="500"/>
- <alpha android:fromAlpha="1.0"
- android:toAlpha="0.0"
- android:duration="500" />
- </set>
OK!