2013-12-15 73 views
1

我目前正在研究一個android項目,我正在嘗試使用片段。我主要工作,但是,我無法得到正確的佈局。設置多個片段的佈局

在佈局中應該有一個從左側的導航抽屜中的幻燈片和右側的導航抽屜中的幻燈片。

在活動的頂部應該有一個片段,並在另一個片段的下面。頂部的片段比下面的片段小。

即使我已經設置了片段的高度,它佔用了整個屏幕,並且兩個片段在下面重疊。下面是一張應該強調我想要實現的圖像。

Screen layout

下面是對FragmentActivity的XML

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    <fragment android:name="com.BoardiesITSolutions.MysqlManager.QueryEditor" 
     android:id="@+id/fragment_query_editor" 
     android:layout_width="match_parent" 
     android:layout_height="10dp"/> 
    <fragment android:name="com.BoardiesITSolutions.MysqlManager.MainContentFragment" 
     android:layout_width="fill_parent" 
     android:layout_height="100dp" /> 
    <ListView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/left_drawer" 
     android:layout_width="280dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:paddingLeft="@dimen/list_padding" 
     android:paddingRight="@dimen/list_padding" 
     android:choiceMode="singleChoice" 
     android:divider="#4e4e4e" 
     android:dividerHeight="1dp" 
     android:background="#111" /> 

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

我從右邊取出導航菜單幻燈片暫且只,而我得到的基本佈局正確

以下是查詢編輯器片段的XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:orientation="vertical" 
    android:background="#c1c1c1c1" > 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="QUERY EDITOR"/> 

</LinearLayout> 

感謝您提供的任何幫助

回答

0

您的抽屜佈局應該是最外面的父級。然後,您應該有一個可用於包含內部UI片段的matchparent高度和寬度的佈局。第二個和第三個佈局應該是您的抽屜中的相關左右layout_gravity集。

總之,外部抽屜包含3個內部佈局。

對不起,我在平板電腦上,所以不能顯示這個給你,但它在這裏解釋。

http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html