Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TranslateAnimated ImageView not clickable after animation [Android]

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?

like image 217
Sephy Avatar asked Aug 03 '10 14:08

Sephy


People also ask

How do I use objectanimator to animate a view?

Here is an example of an ObjectAnimator that moves the view to 100 pixels from the left of the screen in 2 seconds: This example uses the ObjectAnimator.ofFloat () method since the translation values have to be floats. The first parameter is the view you want to animate. The second parameter is the property you are animating.

What is the difference between tweened animation and view animation?

Tweened animation calculates animation information such as size, rotation, start point, and endpoint. These animations are slower and less flexible. An example of View animation can be used if we want to expand a specific layout in that place we can use View Animation. The example of View Animation can be seen in Expandable RecyclerView.

What is the difference between view animation and drawable animation?

These animations are slower and less flexible. An example of View animation can be used if we want to expand a specific layout in that place we can use View Animation. The example of View Animation can be seen in Expandable RecyclerView. 3. Drawable Animation Drawable Animation is used if you want to animate one image over another.

What is the use of view animation?

View Animation can be used to add animation to a specific view to perform tweened animation on views. Tweened animation calculates animation information such as size, rotation, start point, and endpoint. These animations are slower and less flexible.


1 Answers

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);
        }
        });
like image 64
M.ES Avatar answered Sep 25 '22 04:09

M.ES