Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当工具栏存在时,带有片段的android布局会中断_Android_Android Layout_Android Fragments - Fatal编程技术网

当工具栏存在时,带有片段的android布局会中断

当工具栏存在时,带有片段的android布局会中断,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,找不到更合适的标题,但我的问题如下。我有一个LinearLayout,其中包含另一个LinearLayout和一个片段。我还想添加工具栏,但当我这样做时,我只看到工具栏,而另一个屏幕只是白色的 布局如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://sc

找不到更合适的标题,但我的问题如下。我有一个
LinearLayout
,其中包含另一个
LinearLayout
和一个片段。我还想添加
工具栏
,但当我这样做时,我只看到
工具栏
,而另一个屏幕只是白色的

布局如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context="xeniasis.mymarket.MainActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:baselineAligned="false"
        android:weightSum="4">

        <LinearLayout
            android:id="@+id/categories_layout"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:paddingRight="20dp">

            <ExpandableListView
                android:id="@+id/categories_listView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>

        <fragment
            android:id="@+id/mainPane"
            android:name="xeniasis.mymarket.Products"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            tools:layout="@layout/activity_main" />
    </LinearLayout>
</LinearLayout>

只有当我有一个
片段时才会发生这种情况,因为我以前有一个带有静态布局的xml,而
片段现在就是这个xml。

问题是您使用了一个带有

android:orientation="horizontal"
由于工具栏的宽度为
match\u parent
,因此它占据了整个屏幕。 尝试使用

android:orientation="vertical" 

在根布局中,问题是使用了带有

android:orientation="horizontal"
由于工具栏的宽度为
match\u parent
,因此它占据了整个屏幕。 尝试使用

android:orientation="vertical" 

在根布局中

“其他屏幕仅为白色”-片段应该显示什么?@cricket\u 007首先加载
活动\u主
布局。我没有再往前走了。假设根据用户交互情况更改布局好吧,
android:orientation=“horizontal”
显示工具栏的方式似乎不太好。主布局是水平线性布局,第一个子是工具栏,其宽度为“match\u parent”,这会迫使屏幕右侧的所有内容消失。我想说的是,活动的布局应该有
android:orientation=“vertical”
,因为您希望在片段和列表视图的顶部和上方有一个工具栏。“其他屏幕只是白色的”-片段应该显示什么?@cricket\u 007在第一次加载
活动\u main
布局时。我没有再往前走了。假设根据用户交互情况更改布局好吧,
android:orientation=“horizontal”
显示工具栏的方式似乎不太好。主布局是水平线性布局,第一个子是工具栏,其宽度为“match\u parent”,这会迫使屏幕右侧的所有内容消失。我想说的是,活动的布局应该具有
android:orientation=“vertical”
,因为您希望在片段和列表视图的顶部和上方有一个工具栏。