Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓-按钮彼此相邻_Android_Xml_Intellij Idea - Fatal编程技术网

Android 安卓-按钮彼此相邻

Android 安卓-按钮彼此相邻,android,xml,intellij-idea,Android,Xml,Intellij Idea,我很难把按钮放在一起。我已经研究过这个话题,但似乎没有任何帮助 以下是我的XML代码: 下面是它现在的显示方式: 如果我尝试向下移动“回车”按钮,则“清除”按钮将向上移动,反之亦然。我可以左右移动按钮,但不能与另一个按钮在同一条线上现在,您的两个按钮是垂直方向的线性布局的元素。所有元素都在下一个元素的上方显示,因此要使它们并排显示,只需将它们封装在水平LinearLayout容器中即可 <LinearLayout android:layout-width="fill_parent"

我很难把按钮放在一起。我已经研究过这个话题,但似乎没有任何帮助

以下是我的XML代码:

下面是它现在的显示方式:


如果我尝试向下移动“回车”按钮,则“清除”按钮将向上移动,反之亦然。我可以左右移动按钮,但不能与另一个按钮在同一条线上

现在,您的两个按钮是垂直方向的
线性布局的元素。所有元素都在下一个元素的上方显示,因此要使它们并排显示,只需将它们封装在水平
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>


将按钮包装到另一个水平方向的线性布局中写入一些xml kod,不要使用拖放。。。这还不够!我喜欢这个答案。这很简单。但是,我怀疑您可能想将布局展平。阅读这篇文章,它解释了为什么不喜欢嵌套,并提供了其他方法。谢谢!工作得很有魅力!