【发布时间】:2016-11-14 10:34:34
【问题描述】:
我想要一个嵌套的片段,它应该占据其余的空间。问题是它甚至没有显示,因为高度是 1 px。例如,如果我将高度设置为 300 dp,一切看起来都很好。这是我的代码。也许布局无法计算其他两个布局的高度。:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/white_with_divider_bg"
android:id="@+id/firstL">
</RelativeLayout>
<RelativeLayout
android:id="@+id/secondL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
</RelativeLayout>
<FrameLayout
android:id="@+id/child_fragment"
android:layout_height="0dip"
android:layout_width="match_parent"
android:layout_weight="1"/>
</LinearLayout>
应该是这样的:
【问题讨论】:
-
您可以使用单个RelativeLayout,而不是使用所有那些嵌套布局(不利于性能和糟糕的设计)。在这种情况下,甚至是单个 LinearLayout(也更快)。
-
布局很复杂,每个子布局中都有很多视图,因此我只展示了主要逻辑。
-
对于您所展示的内容,单个 LL 就足够了。如果更复杂,请考虑使用单个 RL。
标签: android android-framelayout android-nested-fragment