2015-10-14 76 views

回答

0

您所遇到的行为是,据我所知,预计。然而,有一个setExpanded()方法,它允许您以编程方式关闭/打开AppBarLayout,并可以选择动画过程。因此,您可能可以听取MotionEvent.ACTION_UP事件,并根据AppBar从原始位置走过的距离发起动画以打开或关闭它。

编辑: 这是我刚刚在模拟器上测试的实施运行奇巧:

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); 
    } 
    //... 
} 
0

这可能是晚了一点,但就像在这篇文章中解释说:How to implement snapping in CollapsingToolbarLayout?添加了一个新的捕捉功能。只需添加 app:layout_scrollFlags =“scroll | exitUntilCollapsed | snap” 到您的CollapsingToolbarLayout。希望能帮助到你。