在平板上运行Fragment测试app。结果左右两个Fragment都无法显示。
其中activity_main.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/left_fragment"
android:name="com.example.administrator.fragmenttest.LeftFragment"
android:layout_weight="1"/>
</LinearLayout>
发现
android:orientation="vertical" 与 android:layout_weight="1"冲突了。
layout_weight是水平方向平分屏幕。
所以删了orientation或者改为horizontal就好。