2

我正在尋找最佳做法,當涉及到以下很常見的設置:使用帶抽屜的活動,滾動欄,標籤和不同片段

什麼我目前做的是:

我的主活動有一個導航抽屜和一個工具欄。 當您單擊抽屜內部的其中一個列表項目時,會在工具欄下載入一個片段。一些片段使用viewpager等內部自己的選項卡。

我想利用像滾動等隱藏工具欄的材料功能。完成它是沒有問題的。 但是當只有一些片段想要使用滾動工具欄時會出現問題。如果您可以在底部添加額外的邊距,使用正常的滾動視圖可以解決問題,但是一旦您有鍵盤,滾動錯誤就會陷入困境。使用nestedscrollview可以工作,但不會滾動工具欄。 那麼如何避免滾動工具欄,當我的活動持有的工具欄和一些片段滾動應該使用它和一些不?

建築設計是否錯誤?我想過的另一件事是在每個片段中都有不同的工具欄......但是他們必須共享相同的導航抽屜,所以您必須每次都創建並添加ToggleButton?這是正確的方法嗎?我應該走那條路嗎?我不相信,並希望得到更有經驗的人的意見。這種情況下最好的解決方案是什麼?

感謝您的幫助! 乾杯

編輯: 主要活動

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true"> 


<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/fragment_container_first" 

    > 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     > 


     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?android:attr/actionBarSize" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

     </android.support.v7.widget.Toolbar> 


    </android.support.design.widget.AppBarLayout> 


    <LinearLayout 
     android:id="@+id/owner_main_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/appBar" 
     android:orientation="horizontal" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab_add" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/addicon" 
     app:fabSize="normal" 
     app:layout_anchor="@id/owner_main_container" 
     app:layout_anchorGravity="bottom|right|end" 
     app:layout_behavior="xxx.Classes.Misc.ScrollAwareFABBehavior" 
     /> 

</android.support.design.widget.CoordinatorLayout> 
<!-- The navigation drawer --> 
<android.support.design.widget.NavigationView 
    android:id="@+id/navigation_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:menu="@menu/drawerhost" /> 

+0

請問您可以添加您的代碼。 –

+0

我添加了我的活動佈局代碼 – Patric

+0

是否有一個行爲可以在我的nestedscrollview上設置以避免滾動工具欄?使用的東西,而不是appbar_scrolling_view_behaviour。 只需要一個nestedscrollview,不滾動我的工具欄 – Patric

回答

1

我也使用抽屜式導航欄和工具欄,請從this link 導入項目,並嘗試瞭解如何使用使用抽屜式導航欄和工具欄片段

+0

感謝您的鏈接。將直接看看它 - 然後回來給你 – Patric

+0

你的項目不包括我的用例......沒有滾動工具欄也沒有抽屜改變片段(它確實改變標籤) – Patric

相關問題