我使用CollapsingToolbarLayout
從Android Design Support Library
爲動畫活動中的工具欄。問題是,如果我在動畫中間擡起手指,工具欄不會繼續動畫。它只在屏幕上保持一半顯示。我該如何解決它?Android:自動完成動畫CollapsingToolbarLayout
這裏是一個GIF:http://goo.gl/GQGQqe
謝謝回答。
我使用CollapsingToolbarLayout
從Android Design Support Library
爲動畫活動中的工具欄。問題是,如果我在動畫中間擡起手指,工具欄不會繼續動畫。它只在屏幕上保持一半顯示。我該如何解決它?Android:自動完成動畫CollapsingToolbarLayout
這裏是一個GIF:http://goo.gl/GQGQqe
謝謝回答。
您所遇到的行爲是,據我所知,預計。然而,有一個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);
}
//...
}
這可能是晚了一點,但就像在這篇文章中解釋說:How to implement snapping in CollapsingToolbarLayout?添加了一個新的捕捉功能。只需添加 app:layout_scrollFlags =「scroll | exitUntilCollapsed | snap」 到您的CollapsingToolbarLayout。希望能幫助到你。
gif的鏈接已死 –