Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
812 views
in Technique[技术] by (71.8m points)

android - OnClickListener issues after ImageButton moved after TranslateAnimation

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);      
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...