Kalpana
Kalpana

Reputation: 23

How to animate a view without focusing it

I have a ImageView in NestedScrollView which I am hiding with animation using below method when I scroll up and the ImageView is not visible in the screen.

public static void collapse(final View v) {
        final int initialHeight = v.getMeasuredHeight();

        Animation a = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                if (interpolatedTime == 1) {
                    v.setVisibility(View.GONE);
                } else {
                    v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                    v.requestLayout();
                }
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }
        };

        // 1dp/ms
        a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density) * 4);
        v.startAnimation(a);
    }

But as soon as the animation starts...it scrolls back to the ImageView then hides it. I don't want the ImageView to have focus at the time of animation. I am using animation because when I set the visiblity of ImageView to GONE, I see a flick or blink in my screen.

Upvotes: 0

Views: 42

Answers (0)

Related Questions