本文是在上一篇文章基础上写成的,简单的要死,就不多做解释了,直接上代码和资源,布局与上一篇完全一样,就一张图片;
资源:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1"
android:toAlpha="0"
android:duration="5000"/>
<translate
android:duration="5000"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="100%"
android:toYDelta="100%" />
</set>
代码
package com.example.bujiandonghua;
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.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity implements OnClickListener {
private ImageView iv_zhangxin;
private Button bt_set;
private Animation translationAnimation;
private boolean isRunning;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv_zhangxin = (ImageView) findViewById(R.id.iv_zhangxin);
bt_set = (Button) findViewById(R.id.bt_set);
bt_set.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Animation animationSet = AnimationUtils.loadAnimation(this,
R.anim.tween_set_animation);
iv_zhangxin.startAnimation(animationSet);
}
}