【发布时间】:2015-07-23 20:28:19
【问题描述】:
为了让这个布局发挥作用,我已经苦苦挣扎了好几个小时。
这是我的代码:
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="horizontal"
tools:context=".MainPreviewActivity">
<fragment
android:name="com.apps.foo.CleanPreviewFragment"
android:id="@+id/clean_preview_fragment"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="match_parent">
</fragment>
<fragment
android:name="com.apps.foo.pointop.DirtyPreviewFragment"
android:id="@+id/filters_fragment"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="match_parent">
</fragment>
<fragment
android:name="com.apps.foo.pointop.ProcessedPreviewFragment"
android:id="@+id/processed_preview_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent">
</fragment>
</LinearLayout>
每个片段都是一个简单的RelativeLayout(都具有相同的视图):
<RelativeLayout
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"
tools:context="com.apps.<whatever the fragment name is>">
</RelativeLayout>
现在我想让它像这样工作:
1) 没有嵌套的 layout_weight
2) 根本没有嵌套(例如嵌套前 2 个片段等 等)
3) 视图完成后不使用代码以编程方式执行此操作 渲染。
在我看来,最干净最易读的方法是将片段 1 和片段 2 的方向设置为水平,将片段 3 设置为垂直,但这不起作用。
我还检查了this answer,
但是这家伙,使用带有RelativeLayout 的layout_weight。相对布局会忽略权重,这将不起作用。
任何帮助将不胜感激?
【问题讨论】:
标签: android android-layout android-fragments