2012-04-13 62 views
1

我应该怎么做才能将imageButton移动到新的位置并保持OnClick事件?ImageButton移动后的OnClickListener问题TranslateAnimation

我对这两个问题:

  1. 如果我使用fillAfter(真),的onclick不会带到新的地方。
  2. 如果使用setAnimationListener(onAnimationEnd),并调用layout()将ImageButton移动到新的位置,ImageButton将返回到新的开始位置,为什么?

代码在这里:

tsla = new TranslateAnimation(0.0f,(float) (imgWidth * 0.45)-wh/2,0.0f,(float) (imgHeight * 0.566666667)-wh/2); 
    tsla.setDuration(sleepX); 

    tsla.setAnimationListener(new AnimationListener(){ 
     public void onAnimationStart(Animation arg0) { 
     } 
     public void onAnimationEnd(Animation arg0) { 
      imgBtnChengdu.layout(
       (int) (imgWidth * 0.45), 
       (int) (imgHeight * 0.566666667), 
       (int) (imgWidth - wh - imgWidth * 0.45), 
       (int) (imgHeight - wh - imgHeight * 0.566666667) 
       ); 
     } 
     public void onAnimationRepeat(Animation arg0) { 
     } 
    }); 

    imgBtnChengdu.setAnimation(tsla);  
+0

谢谢,Janusz ... – SICON 2012-04-16 02:41:36

回答

2

的问题是,Android将仅动画按钮的图像到新的地方。

这意味着onClick区域停留在旧地方。您还需要更改动画结尾的按钮位置,将整个按钮移动到新位置,而不仅仅是其视图。

+0

如何移动?设置** imgBtnChengdu.layout **不正确? – SICON 2012-04-13 08:50:15

+0

布局功能只能从Android系统内部调用。更改视图的位置可以通过更改视图的LayoutParameters以及如何实现,取决于您的布局。 – Janusz 2012-04-13 09:33:18

+0

谢谢,让我试试.. – SICON 2012-04-16 01:46:10