0

I am trying to expand and shrink the width of container with animation. I am doing both of those with ValueAnimator and both of those are working fine separately. The expand animation will be perform when the user scroll up the cards and shrink animation will be perform when the user scroll down the cards.

Because all of those cards are in ScrollView container, the user can scroll up / down whenever they want even though the expanding / shrinking Animation is not finished.

To be more clear, it looks like the shrink animation is being triggered when the cards are still expanding. Below is my code for expanding / shrinking.

private void animateResizeWidth(final View vcLogin, int widthReduce){
        ValueAnimator anim;
        if(widthReduce == 0){
            anim = ValueAnimator.ofInt((ScreenUtils.getObjInstance().getPixelFromDPI(CARD_WIDTH) - ScreenUtils.getObjInstance().getPixelFromDPI(widthReduce)), ScreenUtils.getObjInstance().getPixelFromDPI(CARD_WIDTH));
        }else{
            anim = ValueAnimator.ofInt(ScreenUtils.getObjInstance().getPixelFromDPI(CARD_WIDTH), (ScreenUtils.getObjInstance().getPixelFromDPI(CARD_WIDTH) - ScreenUtils.getObjInstance().getPixelFromDPI(widthReduce)));
        }

        final RelativeLayout.LayoutParams finalLp2 = new RelativeLayout.LayoutParams(vcLogin.getLayoutParams());
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int val = (Integer) valueAnimator.getAnimatedValue();
                finalLp2.width = val;
                finalLp2.addRule(RelativeLayout.CENTER_HORIZONTAL);
                vcLogin.setLayoutParams(finalLp2);
                vcLogin.invalidate();
            }
        });
        anim.setDuration(400);
        anim.start();
    }

So, whenever that happen, the size of the cards are being set to regular size and the resize animation won't trigger anymore (Need to restart the Host Activity).

I have tried the answer from here. But, it is not helping me.

My Questions are
1: Is there any other Animation Mechanism that I can use for width animation except ValueAnimator ? I have checked ObjectAnimator but, not supporting. Ref
2: Is that thread issue ?
3: I should not be blocking user from scrolling down just because my expanding animation is not finished. So, what I haven in mind is if the user scroll down, I will just terminate any of my pending animations. Is there any thread-related issue that I need to consider for this approach ? (I have written a Custom ScrollView to detect those scroll-related events.)

I think I am missing a few thread-safe logics in above animation implementation.

Thanks

Community
  • 1
  • 1
Aung Pyae
  • 1,590
  • 2
  • 16
  • 25
  • Thread? You dont use any non UI thread... alsi instead of invalidate(), did you try requestLayout()? – pskink Jan 07 '15 at 10:53
  • Still the same. The sequence is (1) Cards are moving down according to user scroll (2) While moving down, the cards' widths are being expand. When the user scroll up, the sequence is (1) Cards are moving up to previous location [y] (2) the widths of cards are being shrinked. The problem is when user scroll up while the cards are being expand, i think the layout params update from onAnimationUpdate is being interrupted. And after that, any of width animation are not being triggered. – Aung Pyae Jan 07 '15 at 11:28
  • What I mean by thread is, like a "dead lock mechanism". While one thing is doing in progress, the other thing has to wait. In my case, if the other thing is being triggered, the remaining items in the first thing should be abandoned. That logic is being put in place. But, the values are not affecting. Probably because of that onAnimationUpdate async call. – Aung Pyae Jan 07 '15 at 11:32
  • when/where do you call `animateResizeWidth`? – pskink Jan 07 '15 at 11:36

0 Answers0