2014-12-05 16 views
0

在我的layout-sw600dp-land文件夹中,此布局文件用于应用程序启动的主要活动。一旦应用程序启动,两个片段以编程方式添加到相关的框架布局。工具栏被横向推回

此当前布局会导致工具栏被推回到两个框架布局之后。

activity with two fragments with pushed back toolbar

的viewpager片段和右边的片段占用工具栏空间和工具栏被击退他们俩身后。

<LinearLayout 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:orientation="horizontal" > 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     android:orientation="horizontal" > 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/my_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:minHeight="?attr/actionBarSize" 
      app:theme="?attr/ToolBarStyle" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:baselineAligned="false" 
      android:orientation="horizontal" > 

      <FrameLayout 
       android:id="@+id/fragment1" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:paddingRight="4dp" /> 

      <FrameLayout 
       android:id="@+id/fragment2" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:paddingRight="4dp" /> 
     </LinearLayout> 

     <include layout="@layout/nav_drawer_layout" /> 
    </android.support.v4.widget.DrawerLayout> 

</LinearLayout> 

双窗格(片段)工具栏布局的合适语法是什么?

+1

DrawerLayout可处理2个视图。在你的情况下,你有3个(至少)的意见。 – 2014-12-05 06:17:46

+0

@GabrieleMariotti你会如何建议如何创建我想创建的布局类型? – TheSunny 2014-12-05 17:29:22

+0

@GabrieleMariotti在两个框架布局的顶部添加边距允许工具栏变得可见,有没有更好的解决方案呢? – TheSunny 2014-12-05 18:02:45

回答

0

解决!

<LinearLayout 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:orientation="vertical" > 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" > 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/my_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:theme="?attr/ToolBarStyle" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:baselineAligned="false" 
       android:orientation="horizontal" > 

       <FrameLayout 
        android:id="@+id/fragment1" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" /> 

       <FrameLayout 
        android:id="@+id/fragment2" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" /> 
      </LinearLayout> 
     </LinearLayout> 

     <include layout="@layout/nav_drawer_layout" /> 
    </android.support.v4.widget.DrawerLayout> 

</LinearLayout> 

要注意的重要一点是,我想必须要提出的抽屉式导航栏的所有内容上面,即使是工具栏,这就是为什么@ GabrieleMariotti的评论并没有引起我的理想解决方案。使用这种布局,可以显示两个片段,并且可以在操作栏上显示抽屉布局。