【问题标题】:Nested fragment filling the rest of the space嵌套片段填充其余空间
【发布时间】: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


【解决方案1】:

当使用权重时,LineiearLayout 的所有子项都应该有权重,但这对您没有帮助。你应该有 android:id="@+id/child_fragment" 有 height="match_parent" 并删除重量。

应该可以的。

【讨论】:

  • 嗯。您可以尝试的另一种解决方案是将 LiniearLayout 替换为 RelativeLayout 并使用您可以给孩子的上面和下面的属性。
猜你喜欢
  • 1970-01-01
  • 2021-10-29
  • 2019-09-03
  • 2011-12-04
  • 2018-11-11
  • 2015-04-14
  • 2013-03-12
  • 2021-02-06
  • 1970-01-01
相关资源
最近更新 更多