translateAnimation-平移效果

package com.example.user_defined_view;android

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;app

public class MainActivity extends Activity implements OnClickListener {
ImageView image, scale;ide

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.image);
image.setOnClickListener(this);
scale = (ImageView) findViewById(R.id.scale);
scale.setOnClickListener(this);動畫

}this

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.image:
AnimationSet animset = new AnimationSet(true);
AlphaAnimation alphaanim = new AlphaAnimation(1, 0);// 徹底顯示到徹底透明
alphaanim.setDuration(3000);
animset.addAnimation(alphaanim);
image.startAnimation(animset);
break;
case R.id.scale:
// AnimationSet set = new AnimationSet(true);
// ScaleAnimation scaleanim = new ScaleAnimation(0.0f,1 , 0.0f,1,
// Animation.RELATIVE_TO_SELF, 0.5f,
// Animation.RELATIVE_TO_SELF, 0.5f);
// scaleanim.setDuration(3000);
// set.addAnimation(scaleanim);
// scale.startAnimation(set);
// 平移操做
// 動畫
AnimationSet transset=new AnimationSet(true);

TranslateAnimation translate=new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 3f
,Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,0.0f);

translate.setDuration(3000);
transset.addAnimation(translate);
scale.startAnimation(transset);


break;
default:
break;
}get

}
}animation

相關文章
相關標籤/搜索