在TranslateAnimation之后ImageButton移动后,OnClickListener发出问题

时间:2012-04-13 08:35:04

标签: android onclicklistener

如何将imageButton移动到新的位置并保持OnClick事件?

我有两个问题:

  1. 如果我使用fillAfter(true),则onclick将不会转到新位置。
  2. 如果使用setAnimationListener(onAnimationEnd),并调用layout()将ImageButton移动到新的位置,ImageButton将返回到新的起始位置,为什么?
  3. 代码在这里:

        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);      
    

1 个答案:

答案 0 :(得分:2)

问题在于,Android只会将按钮图像设置为新位置。

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