我对这个指令 TranslateAnimation 有问题,实际上当启动动画以向后移动帧(从右到左动画)时,剪切右侧的帧,只是释放触摸屏时留在屏幕外的部分。 ..相反,当我运行动画以使框架消失(从左侧到右侧)..示例:
在屏幕中间拖动手指,最后松开 .. 动画开始,框架消失 .. 故障:如果我在屏幕上从屏幕中间到末尾随机点再次按下它,动画将从我按下的点
我的代码:
RelativeLayout.LayoutParams params = null;
int x;
int offset;
int tmp= 0;
int avviato = 0;
@Override
public boolean onTouch(View v, android.view.MotionEvent event) {
// TODO Auto-generated method stub
FrameLayout frame = (FrameLayout) this.findViewById(R.id.frame1);
if(v == findViewById(R.id.frame1)){
if(event.getAction() == android.view.MotionEvent.ACTION_MOVE){
x= (int) event.getRawX();
if (tmp==0){
offset = x;
tmp = 1;
}
if(offset < (x - WHIDTH /5) || offset > (x + WHIDTH /5) || avviato ==1)
{
params = new RelativeLayout.LayoutParams((int) (WHIDTH ), (int) (HEIGHT));
params.leftMargin = x;
params.topMargin = (int) (0);
frame.setLayoutParams(params);
avviato = 1;
}
}//fine get action
if(event.getAction() == android.view.MotionEvent.ACTION_UP){
tmp = 0;
avviato = 0;
x= (int) event.getRawX();
if(x > (WHIDTH /3))
{
Animation animation= new TranslateAnimation(x - x, WHIDTH , 0, 0);
animation.setDuration(1000);
animation.setFillAfter(true);
frame.startAnimation(animation);
}
if(x < (larghezza /3))
{
Log.i("xxXxxanommmm", toString().valueOf(x));
Animation animation= new TranslateAnimation(x-x,0 -x, 0, 0);
animation.setDuration(1000);
animation.setFillAfter(true);
frame.startAnimation(animation);
}
}
return true;
}//fine if v
return false;
}//fine touch