AnimationActivity.java
Dosyayı İndir
package com.godoro.androidgraphics;
import android.animation.*;
import android.app.*;
import android.graphics.*;
import android.os.Bundle;
import android.view.*;
import android.view.animation.*;
import android.widget.*;
public class AnimationActivity extends Activity {
private TextView textView;
private ImageView imageView;
private EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation);
textView=(TextView) findViewById(R.id.textView);
imageView=(ImageView) findViewById(R.id.imageView);
editText=(EditText) findViewById(R.id.editText);
}
public void onClickMove(View view){
// SDK < 11
Animation translate=new TranslateAnimation(0,50,0,100);
translate.setDuration(1000);
textView.startAnimation(translate);
ObjectAnimator translateX=ObjectAnimator.ofFloat(textView,"translationX",100);
translateX.setDuration(1000);
translateX.start();
ObjectAnimator translateY=ObjectAnimator.ofFloat(textView,"translationY",100);
translateY.setDuration(1000);
translateY.start();
ObjectAnimator rotate=ObjectAnimator.ofFloat(textView,"rotation",180);
//rotate.setRepeatCount(10);
rotate.setDuration(1000);
rotate.start();
ObjectAnimator scaleX=ObjectAnimator.ofFloat(textView,"scaleX",0.5f);
scaleX.setDuration(1000);
scaleX.start();
ObjectAnimator scaleY=ObjectAnimator.ofFloat(textView,"scaleY",2);
scaleY.setDuration(1000);
scaleY.start();
}
public void onClickChange(View view){
ObjectAnimator textColor=ObjectAnimator.ofInt(textView,"textColor",Color.BLUE,Color.RED);
textColor.setDuration(1000);
textColor.start();
ObjectAnimator imageAlpha=ObjectAnimator.ofFloat(imageView,"alpha", 0.5f, 1f, 0f);
imageAlpha.setDuration(1000);
imageAlpha.start();
}
public void onClickSet(View view){
AnimatorSet animatorSet=new AnimatorSet();
// animatorSet.playSequentially(
// ObjectAnimator.ofFloat(editText,"translationX",50),
// ObjectAnimator.ofFloat(editText,"translationY",-50));
// animatorSet.playTogether(
// ObjectAnimator.ofFloat(editText,"translationX",50),
// ObjectAnimator.ofFloat(editText,"translationY",-100));
animatorSet
.play(ObjectAnimator.ofFloat(editText,"translationX",50,100))
.after(ObjectAnimator.ofFloat(editText,"translationY",-50,-100))
.before(ObjectAnimator.ofInt(editText,"textColor",Color.BLUE,Color.RED));
animatorSet.start();
}
}
Dosyayı İndir