1

I am using CollapsingToolbarLayout from Android Design Support Library for animating toolbar in an activity. Problem is, that if i lift my finger in the middle of animation, toolbar doesn't continue with animating. It just stays half displayed on the screen. How can i fix it?

Here is a gif: http://goo.gl/GQGQqe

Thanks for answer.

Pepcox
  • 11
  • 3

2 Answers2

0

The behaviour you are experiencing is, near as I understand, expected. However, there is a setExpanded() method which allows you to close/open the AppBarLayout programmatically, with the option of animating the process. As such, you may be able to listen for MotionEvent.ACTION_UP events and launch an animation to open or close the it based on how far the AppBar has travelled from its original positions.

Edit: Here's an implementation I just tested on an emulator running KitKat:

public class MainActivity extends AppCompatActivity {
    //...
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_UP) {
            if (appBarLayout.getY() != 0) {
                //User has just finished interacting with the screen
                //and the AppBar is not fully expanded. So, to close 
                //it with an animation...
                appBarLayout.setExpanded(false, true);
            }
        }
        return super.dispatchTouchEvent(ev);
    }
    //...
}
PPartisan
  • 8,173
  • 4
  • 29
  • 48
0

This might be a bit later, but just like explained in this post: How to implement snapping in CollapsingToolbarLayout? a new snapping feature was added. Just add app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" To your CollapsingToolbarLayout. Hope it helps.

p_0g_amm3_
  • 451
  • 6
  • 14