当工具栏存在时,带有片段的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”
,因为您希望在片段和列表视图的顶部和上方有一个工具栏。