package
org.myjob;
import
android.support.v7.app.AppCompatActivity;
import
android.os.Bundle;
import
android.view.View;
import
android.view.animation.Animation;
import
android.view.animation.AnimationUtils;
import
android.widget.Button;
import
android.widget.ImageView;
public
class
MyJob
extends
AppCompatActivity {
private
ImageView image;
private
Button button1, button2;
private
Animation up, down;
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
image = (ImageView) findViewById(R.id.image);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(
new
View.OnClickListener() {
@Override
public
void
onClick(View view) {
setAnimation(up);
}
});
button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(
new
View.OnClickListener() {
@Override
public
void
onClick(View view) {
setAnimation(down);
}
});
up = AnimationUtils.loadAnimation(
this
, R.anim.up);
down = AnimationUtils.loadAnimation(
this
, R.anim.down);
}
private
void
setAnimation(Animation animation) {
animation.setFillAfter(
true
);
animation.setAnimationListener(
new
Animation.AnimationListener() {
@Override
public
void
onAnimationEnd(Animation animation) {
}
@Override
public
void
onAnimationRepeat(Animation animation) {
}
@Override
public
void
onAnimationStart(Animation animation) {
}
});
image.startAnimation(animation);
}
}