【发布时间】:2014-02-06 14:16:28
【问题描述】:
我正在尝试创建一个包含三个片段的简单布局。在左边,我想要两个片段彼此重叠,每个片段占据屏幕高度的 50%。在右边,我想要一个大的容器片段,像这样:
+-----+-----------------+
| f1 | detail_container|
| | |
+-----+ |
| f2 | |
| | |
+-----+-----------------+
我让它与两个LinearLayouts 一起工作,使用layout_height="0dp" 和layout_weight="1",但我得到消息它对性能不利,所以我开始使用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值不知道怎么填。我尝试了各种值,但它们似乎都必须是绝对的(我不想要)。
【问题讨论】:
-
添加
View与android:layout_height="0dip"和android:layout_centerVertical="true,然后使用android:layout_above="<id>"和android:layout_above="<id>"将其中一个对齐在其上方和下方对齐。 -
@hypd09 我将如何定义它们以填充剩余空间?另外,感觉有点hackish。
-
只需设置
android:layout_height="match_parent"。RelativeLayout用于设置关系,这没什么不好。
标签: android android-layout android-fragments android-relativelayout