【问题标题】:How to stack two LinearLayouts?如何堆叠两个LinearLayouts?
【发布时间】:2015-11-08 05:27:27
【问题描述】:

我在将两个线性布局堆叠(显示块级别)时遇到问题。相反,它们是并排的。

感谢任何帮助。

这是我的 XML 问题所在。 Stack1Stack2 是有问题的两个 LinearLayouts 的 ID。我用... 简化了另一个线性布局以节省空间。

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id="@+id/frame"
    android:layout_weight="0.8">

     <LinearLayout
     ...></LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:orientation="horizontal">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:id="@+id/Stack1">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#ffffff"
                android:gravity="center"
                android:layout_marginTop="3dp"
                android:layout_marginBottom="1dp" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:id="@id+/Stack2>

            <ImageButton
                android:layout_width="45dp"
                android:layout_height="45dp"
                android:background="#00010102"
                android:layout_margin="10dp"
                android:scaleType="fitCenter" />

            <ImageButton
                android:layout_width="45dp"
                android:layout_height="45dp"
                android:background="#00010102"
                android:layout_margin="10dp"
                android:scaleType="fitCenter" />

            <ImageButton
                android:layout_width="45dp"
                android:layout_height="45dp"
                android:background="#00010102"
                android:layout_margin="10dp"
                android:scaleType="fitCenter" />

            <ImageButton
                android:layout_width="45dp"
                android:layout_height="45dp"
                android:background="#00010102"
                android:layout_margin="10dp"
                android:scaleType="fitCenter" />

            <ImageButton
                android:layout_width="45dp"
                android:layout_height="45dp"
                android:background="#00010102"
                android:layout_margin="10dp"
                android:scaleType="fitCenter" />
        </LinearLayout>
    </LinearLayout>

</FrameLayout>

【问题讨论】:

  • 开始,对于外部的LinearLayout,更改为:android:orientation="vertical"

标签: android android-layout android-linearlayout


【解决方案1】:

作为 Stack1 和 Stack2 的父级的 LinearLayout 被定义为水平的。将其垂直放置以防止并排放置。

【讨论】:

  • 天哪,当吉特!这样的菜鸟错误。感谢您的帮助!
猜你喜欢
  • 2021-12-22
  • 1970-01-01
  • 1970-01-01
  • 2020-01-02
  • 1970-01-01
  • 2022-01-07
  • 2014-05-29
  • 2011-12-22
  • 1970-01-01
相关资源
最近更新 更多