位移动画
位移动画
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); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。