Android-按钮彼此相邻 [英] Android - Buttons next to each other

查看:86
本文介绍了Android-按钮彼此相邻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将按钮彼此相邻时遇到麻烦.我已经研究了该主题,但似乎无济于事.

I'm having trouble putting buttons next to eachother. I have researched the topic, but nothing seems to have helped.

这是我的XML代码:链接

Here is my XML code: Link

这是现在的显示方式: 我的屏幕

Here is how it displays now: My screen

如果我尝试将Enter按钮向下移动,则clear按钮将向上移动,反之亦然.我可以左右移动按钮,但不能与另一个按钮在同一行

If I try to move the enter button down, the clear button goes up and vice versa. I can move the buttons from side to side, but never on the same line as another button

推荐答案

现在,您的两个按钮是垂直方向LinearLayout的元素.所有元素都在下一个元素上方显示,因此要使其并排显示,您只需将它们封装在水平的LinearLayout容器中即可.

Right now your two buttons are elements of a vertically oriented LinearLayout. All elements appear one above the next, so to get them to display side-by-side, you need to simply enclose them in a horizontal LinearLayout container.

<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>

这篇关于Android-按钮彼此相邻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆