在写布局文件的时候,前提时activity对应留给fragment的布局时match_patch即留给足够的空间给fragment
如下:
fragment.xml
-
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:android=""
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:orientation="horizontal"
-
android:background="#ffbac85d">
- </LinearLayout>
当添加这个文件到activity的布局中的时候,居然不会显示fragment的布局.
然而我将LinearLayout替换程RelativeLayout的时候,布局居然出现了。实在是不明白其诡异之处。
activity的布局文件:
点击(此处)折叠或打开
-
<LinearLayout xmlns:android=""
-
xmlns:tools="" android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:orientation="vertical">
-
这个linearLayout就是fragment的容器<-->
-
<LinearLayout
-
android:layout_width="match_parent"
-
android:layout_height="0dp"
-
android:layout_weight="3"
-
android:background="#ffc8653a"
-
android:id="@+id/fragment"
-
android:orientation="horizontal">
-
-
</LinearLayout>
-
-
<LinearLayout
-
android:layout_width="match_parent"
-
android:layout_height="0dp"
-
android:orientation="horizontal"
-
android:layout_weight="1">
-
-
<EditText
-
android:layout_width="0dp"
-
android:layout_height="wrap_content"
-
android:id="@+id/mainEditText"
-
android:layout_weight="1" />
-
-
<Button
-
android:layout_width="0dp"
-
android:layout_height="wrap_content"
-
android:text="New Button"
-
android:id="@+id/mainButton"
-
android:layout_weight="1" />
-
-
-
</LinearLayout>
-
- </LinearLayout>