【问题标题】:How to place a LinearLayout below a LinearLayout inside another RelativeLayout?如何在另一个 RelativeLayout 内的 LinearLayout 下方放置一个 LinearLayout?
【发布时间】:2014-07-24 00:26:33
【问题描述】:

我试图将 à LinearLayout 放置在另一个 RelativeLayout 内的 LinearLayout 下方?

<ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" >
<RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="top"
                >

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/background_linearlayout_reportdelay"

                 >
           </LinearLayout>

    </RelativeLayout>
    </ScrollView>

有什么办法可以做到吗?

谢谢

【问题讨论】:

  • 为什么?如果在 RelativeLayout 中只有 2 个元素,则可以使用垂直 LinearLayout 来替换它。或者,如果子 LinearLayout 的元素很少,则放弃 LinearLayout 并将它们全部直接放在 RelativeLayout 中。
  • 谢谢,我用垂直的 LinearLayout 替换 RelativeLayout 并且它可以工作。

标签: android android-layout android-linearlayout


【解决方案1】:
<RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/layout1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="top">

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/background_linearlayout_reportdelay"
                android:layout_below="@+id/layout1">
           </LinearLayout>

    </RelativeLayout>

【讨论】:

    【解决方案2】:

    试试这个方法,希望能帮助你解决问题。

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/background_linearlayout_reportdelay" />
    
            </LinearLayout>
    </ScrollView>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-26
      • 1970-01-01
      相关资源
      最近更新 更多