使用多个片段设置布局

时间:2013-12-15 17:33:30

标签: android android-layout android-fragments

我目前正在开发一个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>

感谢您提供的任何帮助

1 个答案:

答案 0 :(得分:0)

您的抽屉布局应该是最外层的父级。然后,您应该具有可用于包含内部UI片段的matchparent高度和宽度的布局。第二和第三个布局应该是您的抽屉滑动,并设置相关的左右layout_gravity。

总之,外部抽屉包含3个内部布局。

抱歉,我在平板电脑上,因此无法为您显示此内容,但在此处对此进行了解释。

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

相关问题