2015-10-14 75 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。希望能幫助到你。