位移动画
public class MainActivity extends Activity implements OnClickListener {
private TextView tv_text;
private TranslateAnimation animation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_text = (TextView) findViewById(R.id.tv_text);
tv_text.onWindowFocusChanged(true);
//int width = tv_text.getWidth();
//int measuredWidth = tv_text.getMeasuredWidth();
int www = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
int hhh = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
this.tv_text.measure(www, hhh);
// 获取控件的宽度
int realitemWidth=this.tv_text.getMeasuredWidth();
int realitemHeight=this.tv_text.getMeasuredHeight();
animation = new TranslateAnimation(0, realitemWidth,0, 0);
animation.setDuration(2000);//设置动画持续时间
animation.setFillAfter(true);
//animation.setRepeatCount(1);//设置重复次数
tv_text.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
tv_text.startAnimation(animation);
Toast.makeText(this, "jife", 0).show();
this.overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
}
}