我正在尝试使用三个片段创建一个简单的布局.在左边,我想要两个碎片,每个碎片占据屏幕高度的50%.在右边,我想要一个大容器片段,如下所示: +-----+-----------------+| f1 | detail_container||
+-----+-----------------+ | f1 | detail_container| | | | +-----+ | | f2 | | | | | +-----+-----------------+
我使用layout_height =“0dp”和layout_weight =“1”使用了两个LinearLayouts,但是我得到的信息是性能不好,所以我开始使用RelativeLayout.我现在拥有的是:
<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:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
android:showDividers="middle"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1" >
<fragment
android:id="@+id/fragment1"
android:name="com.example.Fragment1"
android:layout_width="wrap_content"
android:layout_height=""
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
tools:layout="@android:layout/list_content" />
<fragment
android:id="@+id/fragment2"
android:name="com.example.Fragment2"
android:layout_width="wrap_content"
android:layout_height=""
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
tools:layout="@android:layout/list_content" />
</RelativeLayout>
<FrameLayout
android:id="@+id/action_detail_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" />
</LinearLayout>
我不知道如何填写两个片段的layout_height值.我尝试了各种各样的价值观,但它们似乎都必须是绝对的(我不想要).
这是我的解决方案,有一个常见的解决方法,以避免嵌套权重:<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:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
android:showDividers="middle"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1" >
<View android:id="@+id/dummyView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerInParent="true"/>
<fragment
android:id="@+id/fragment1"
android:name="com.example.Fragment1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignTop="@id/dummyView"
tools:layout="@android:layout/list_content" />
<fragment
android:id="@+id/fragment2"
android:name="com.example.Fragment2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignBottom="@id/dummyView"
tools:layout="@android:layout/list_content" />
</RelativeLayout>
<FrameLayout
android:id="@+id/action_detail_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" />
</LinearLayout>
