TranslateAnimated ImageView not clickable after animation [Android]

拈花ヽ惹草 提交于 2019-12-30 03:16:08

问题


I have 2 ImageViews that I translate from the top of the screen to the bottom. these views are infalted from xml and the animation is added from java code. The animation works perfectly, but the onClickListener I added in java code doesn't seem to work. I used fillAfter attribute of the animation to make the iamges stay at their arrival after the translation, but THESE images aren't clickable anymore... However, their position before translation remains clickable... I can't see the logic of this. Could anyone give me some piece of advice about that?


回答1:


This is because Animations affects only the drawing of widget. However, The real Location is not affected -It is still in the previous one-.

To overcome this problem, you need to update the layout parameters of the ImageView manually by installing an animation listener as follows:

Animation.setAnimationListener(new AnimationListener() {
        public void onAnimationStart(Animation arg0) {

        }

        public void onAnimationRepeat(Animation arg0) {
            //TODO Auto-generated method stub
        }

        public void onAnimationEnd(Animation arg0) {
            android.widget.LinearLayout.LayoutParams params = new LayoutParams(
            android.widget.LinearLayout.LayoutParams.FILL_PARENT,
            android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
            params.topMargin = addLocationButton.getTop()-100;

            ImageView.setLayoutParams(params);
        }
        });


来源:https://stackoverflow.com/questions/3397370/translateanimated-imageview-not-clickable-after-animation-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!