OnClickListener问题TranslateAnimation后后的ImageButton移动 [英] OnClickListener issues after ImageButton moved after TranslateAnimation

查看:119
本文介绍了OnClickListener问题TranslateAnimation后后的ImageButton移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎么办的ImageButton的移动到一个新的订货量大,保持OnClick事件?

我对这个两个问题:

  1. 如果我用fillAfter(真),的onclick不会带到新的地方。​​
  2. 如果使用setAnimationListener(onAnimationEnd)和呼叫布局()到的ImageButton移动到一个新的地方,ImageButton的将回到新的开始的地方,为什么

codeS位置:

  TSLA =新TranslateAnimation(0.0,(浮动)(imgWidth * 0.45)-WH / 2,0.0f,(浮动)(imgHeight * 0.566666667)-WH / 2);
    tsla.setDuration(sleepX);

    tsla.setAnimationListener(新AnimationListener(){
        公共无效onAnimationStart(动画为arg0){
        }
        公共无效onAnimationEnd(动画为arg0){
             imgBtnChengdu.layout(
                (中间体)(imgWidth * 0.45),
                (INT)(imgHeight * 0.566666667)
                (INT)(imgWidth  -  WH  -  imgWidth * 0.45),
                (INT)(imgHeight  -  WH  -  imgHeight * 0.566666667)
                );
        }
        公共无效onAnimationRepeat(动画为arg0){
        }
    });

    imgBtnChengdu.setAnimation(TSLA);
 

解决方案

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

这意味着onClick的区域停留在老地方。你还需要改变在动画结束按钮的位置,整个按钮移动到新的地方,不仅其观点。

what should I do to move the imageButton to a new palce and keep the OnClick event?

I have two questions on this:

  1. If I use fillAfter(true), the onclick will not taken to the new place.
  2. If use setAnimationListener(onAnimationEnd), and call layout() to move the ImageButton to a new place, the ImageButton will back to new beginning place, why?

codes here:

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

解决方案

The problem is that that Android will only animate the Image of the Button to the new place.

This means the onClick Area stays at the old place. You also need to change the position of the button at the end of the Animation to move the whole button to the new place and not only its View.

这篇关于OnClickListener问题TranslateAnimation后后的ImageButton移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆