2012-04-13 64 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