【发布时间】:2016-02-08 13:09:59
【问题描述】:
我在水平线性布局中有三个 imageButton,我想在左上 imageButton 的正下方再添加一个 imageButton(当左上 imageButton 开始和结束时,我希望它下面的 imageButton 也一样)。一切都在垂直线性布局中。我无法将向下的 imageButton 与向上的垂直对齐。我怎样才能做到这一点?有什么想法吗?
我的代码是这样的:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:gravity="center">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton11"
android:background="@drawable/image"
android:layout_gravity="center"
android:layout_marginRight="30dp"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton12"
android:background="@drawable/image"
android:layout_gravity="center"
android:layout_marginRight="30dp"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton13"
android:background="@drawable/image"
android:layout_gravity="center"
android:layout_marginRight="30dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:gravity="left">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton14"
android:background="@drawable/image"
android:layout_marginRight="30dp"/>
</LinearLayout>
【问题讨论】:
-
你从这段代码中得到了什么结果,你能发一个截图或img吗?
-
它将我的最后一个 imageButton 放在其他三个之下,但在开始的第一个之前。所以有一个(空格,然后是三个imageuttons)-->所有这些在一行中,然后还有另一个imageButton,在空格下面
-
这令人困惑。您应该尝试发布屏幕截图。否则尝试 RelativeLayout 并使用 android:layout_below
-
@Mary “它把我的最后一个 imageButton 放在其他三个之下,但在开始的第一个之前”。我不知道你是什么意思..
-
顺便说一下,您不需要使用相对布局来将一个视图放在另一个视图下方,也可以使用线性布局来完成。屏幕截图将使我们更轻松地提供帮助。
标签: android android-studio vertical-alignment screens