0

我目前有一個使用TabLayout的ViewPager。我根據ViewPager的頁數動態地向TabLayout添加元素。使用ViewPager將DrawerLayout添加到TabLayout中

我想在TabLayout的左邊添加一個帶有漢堡圖標的DrawerLayout。滾動TabLayout時,該漢堡圖標應保持可見。

我嘗試使用父親RelativeLayout在TabLayout旁邊添加DrawerLayout而沒有任何成功。

這裏是我想怎樣做:

enter image description here

這是當前XML:

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <android.support.v4.widget.DrawerLayout 
       android:id="@+id/drawer_layout" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 

       <!-- Side navigation drawer UI --> 
       <ListView 
        android:id="@+id/navList" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_gravity="left|start" 
        android:background="#ffeeeeee"/> 

     </android.support.v4.widget.DrawerLayout> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/drawer_layout" 
      app:tabMaxWidth="0dp" 
      app:tabMode="fixed" 
      app:tabGravity="fill"/> 
      </RelativeLayout> 

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

    ... 
    ... 
    ... 

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

回答

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/lib/com.app.chasebank" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="?attr/actionBarSize" 
     android:background="#ef453e" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ef453e" 
     android:minHeight="?attr/actionBarSize" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:tabIndicatorColor="@android:color/white" 
     app:tabIndicatorHeight="5dp" /> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <android.support.v4.view.ViewPager 
      android:id="@+id/pager" 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent"/> 
     </RelativeLayout> 
     <ListView 
      android:id="@+id/listDrawer" 
      android:layout_width="240dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="right" 
      android:choiceMode="singleChoice" 
      android:background="#FF0000"/> 
    </android.support.v4.widget.DrawerLayout> 

</LinearLayout> 

我也工作在相同的任務,在這裏是我所做的。

相關問題