[英]Android translate animation from view
使用翻译动画类
View view1 = (View)findViewById(R.id.view_id);
//defining an animation to scroll the view and the direction
TranslateAnimation mAnimation = new TranslateAnimation(view1.getX(),180,0,0);
// time it will take to finish reach destination, this means how fast the view will translate
mAnimation.setDuration(1000);
// repetition
mAnimation.setRepeatMode(Animation.RESTART);
mAnimation.setRepeatCount(Animation.ABSOLUTE);
view.setAnimation(mAnimation);
TranslateAnimation(value1, value2, value3, value4)
指示TranslateAnimation(value1, value2, value3, value4)
的开始坐标和结束坐标。 它还暗示了翻译的方向。 view1.getX()
将获取当前位置。
如果您不想使用Translate类,则可以定期更新时间位置。 大概每隔一秒钟。 您可以使用此代码
View view = new View(this);
while(true){
sleep(1000);
view.setX(view.getX() + 1);
// define a condition to stop;
}
view.getX()将返回视图的当前位置,然后以规则的间隔(1秒)将其增加一个值,每次执行该行时,它都会获取当前位置并增加该位置。 这应该在线程中完成,因为UI线程可能无法有效处理它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.