【问题标题】:Android - Buttons next to each otherAndroid - 彼此相邻的按钮
【发布时间】:2013-12-26 21:11:13
【问题描述】:
我无法将按钮放在一起。我已经研究过这个话题,但似乎没有任何帮助。
这是我的 XML 代码:Link
这是它现在的显示方式:
My screen
如果我尝试向下移动输入按钮,清除按钮会向上移动,反之亦然。我可以左右移动按钮,但不能与另一个按钮在同一行
【问题讨论】:
标签:
android
xml
intellij-idea
【解决方案1】:
现在您的两个按钮是垂直方向的LinearLayout 的元素。所有元素都出现在下一个之上,因此要让它们并排显示,您只需将它们包含在水平的 LinearLayout 容器中。
<LinearLayout android:layout-width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter"
android:id="@+id/enter"
android:layout_gravity="center"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:id="@+id/clear"
android:layout_gravity="bottom"/>
</LinearLayout>
【讨论】:
-
我喜欢这个答案。很简单。但是,我怀疑您可能想要展平您的布局。阅读此article 它解释了为什么不首选嵌套并提供替代方法。
-