尷尬的app:layout_scrollFlags="scroll|enterAlways" 配合Drawer

來源:互聯網
上載者:User

標籤:

昨天想到了NavigationDrawer中Item點擊的問題。

點擊Drawer中的一個Item需要到一個新的頁面,你是應該開啟一個新的Activity呢還是直接用fragment呢?

如果開啟新的activity,那麼新的Activity覆蓋,Drawer按鈕就會消失;當然你也可以在新的Activity上加同樣的NavigationDrawer,但是那樣太浪費資源了。

但如果你用fragment,那麼你只需要ToolBar下面的地區,整個作為一個可替換的container,然後不同的fragment進行replace就行了。很多App都是這樣做的,比如Google+,比如知乎等等,這樣他們在切換左側的Drawer Item的時候,只需要replace container(不要忘了把fragment入棧)。

 

 

可是,如果你的App有一個ViewPager(FragmentPagerAdapter)呢?其實也是可以的,只需要把ToolBar下面的地區抽離出來,作為fragment的container就行了,然後在MainActivity啟動的時候啟動一個MainFragment,裡麵包含:

tabLayout
viewPager

。

唯專屬一個問題:如果你的應用想要實現ToolBar的動態摺疊,就像這樣:

 

我把ToolBar下面的地區提取出來了,如下,content_main是一個空白的layout,也就是container,activity啟動時我可以往裡面插入一個含有tabLayout和viewPager的fragment。不知道我的意思表達清楚沒有。。

 

 

我唯一見到的app:layout_scrollFlags="scroll|enterAlways" 使用情境是在ToolBar標籤中設定,與CoordinatorLayout配合對ToolBar進行滾動時隱藏。

 

首先,app:layout_scrollFlags是AppBarLayout的屬性。

AppBarLayout is a vertical LinearLayout which implements many of the features of material designs app bar concept, namely scrolling gestures.

Children should provide their desired scrolling behavior through setScrollFlags(int) and the associated layout xml attribute: app:layout_scrollFlags.

This view depends heavily on being used as a direct child within a CoordinatorLayout. If you use AppBarLayout within a different ViewGroup, most of it‘s functionality will not work.

 

尷尬的app:layout_scrollFlags="scroll|enterAlways" 配合Drawer

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.