Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.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_Android Layout_Positioning_Android Button - Fatal编程技术网

Android 同一行上的多个按钮/对象

Android 同一行上的多个按钮/对象,android,android-layout,positioning,android-button,Android,Android Layout,Positioning,Android Button,我希望在同一行上有一个按钮相邻,我希望在编辑文本旁边有一个按钮 我有Eclipse插件,所以我既有图形布局,也有文本。我不能发布图像,但我会描述它:它有两个文本视图(不相关),后面是一个编辑文本,然后在下一行有一个小的未标记的按钮。接下来的四行是标记为转弯N、转弯E、转弯S和转弯W的按钮 因此,在EditText旁边是我希望无标题的按钮的位置,我希望N、E、S、W按钮的设置方式类似于指南针。但是,当我尝试在GUI上拖动它们时,它会将它们绑定到行,并且每当我尝试更改布局时,它会影响所有内容,而不仅

我希望在同一行上有一个按钮相邻,我希望在编辑文本旁边有一个按钮

我有Eclipse插件,所以我既有图形布局,也有文本。我不能发布图像,但我会描述它:它有两个
文本视图
(不相关),后面是一个
编辑文本
,然后在下一行有一个小的未标记的
按钮
。接下来的四行是标记为转弯N、转弯E、转弯S和转弯W的按钮

因此,在
EditText
旁边是我希望无标题的
按钮的位置,我希望N、E、S、W
按钮的设置方式类似于指南针。但是,当我尝试在GUI上拖动它们时,它会将它们绑定到行,并且每当我尝试更改布局时,它会影响所有内容,而不仅仅是我右键单击的一个对象


如何解决这个问题?

如果没有xml,我真的说不上来,但是如果你想以compas的方式定位按钮,你应该尝试创建方形相对布局,将按钮放在它上面,然后将按钮放在父级的顶部、左侧、右侧和底部

如果没有xml,我真的说不上来,但是,如果您想以类似compas的方式定位按钮,您应该尝试创建方形相对布局,将按钮放置在其上,然后将按钮定位在父级的顶部、左侧、右侧和底部,如下所示:

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/textView1"
        android:text="TextView" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/textView2"
        android:layout_toLeftOf="@+id/button1" >
    </EditText>

    <Button
        android:id="@id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/textView2"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/editText1"
        android:layout_centerHorizontal="true"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/button2"
        android:layout_toLeftOf="@id/button2"
        android:text="Button" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/button2"
        android:layout_toRightOf="@id/button2"
        android:text="Button" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/button4"
        android:layout_toLeftOf="@id/button4"
        android:text="Button" />

</RelativeLayout>

类似这样的内容:

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/textView1"
        android:text="TextView" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/textView2"
        android:layout_toLeftOf="@+id/button1" >
    </EditText>

    <Button
        android:id="@id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/textView2"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/editText1"
        android:layout_centerHorizontal="true"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/button2"
        android:layout_toLeftOf="@id/button2"
        android:text="Button" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/button2"
        android:layout_toRightOf="@id/button2"
        android:text="Button" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/button4"
        android:layout_toLeftOf="@id/button4"
        android:text="Button" />

</RelativeLayout>


谢谢,这非常有帮助,现在我的XML图形布局视图正按我所希望的方式显示它。(我还添加了几个按钮),但是,现在在我的Java文件中,引用main的所有内容都有错误。在“setContentView(R.layout.main);”下,它显示错误:“main无法解析或不是字段。”我的xml文件没有显示任何错误,并且我已经尝试重新启动eclipse,我找不到任何错误。有什么建议吗?谢谢@Zeldarulah尝试清理您的项目(在菜单
project->clean
)并检查您是否从包中导入了正确的
R
类(使用
CTRL+SHIFT+O
)(而不是
import android.R;
)。我确实有“import android.R;”,但我尝试了project->clean和CTRL+SHIFT+O,但没有改变它。“import android.R;”是否应该有所不同?再次感谢。@Zeldarulah那行
导入android.R
隐藏您生成的项目
R
类,android找不到布局ID。删除该行,您应该就可以了。(如果您使用了
android.R
名称空间的某些部分,那么不要导入
import android.R;
,只需在需要的地方使用
android.R.something
)好吧,这就解决了它!非常感谢。我不太清楚为什么进口会引起问题,但非常感谢。如果我可以投票给你的答案,我会的,但是我的代表率仍然太低。谢谢,这非常有帮助,现在我的XML图形布局视图正按照我想要的方式显示它。(我还添加了几个按钮),但是,现在在我的Java文件中,引用main的所有内容都有错误。在“setContentView(R.layout.main);”下,它显示错误:“main无法解析或不是字段。”我的xml文件没有显示任何错误,并且我已经尝试重新启动eclipse,我找不到任何错误。有什么建议吗?谢谢@Zeldarulah尝试清理您的项目(在菜单
project->clean
)并检查您是否从包中导入了正确的
R
类(使用
CTRL+SHIFT+O
)(而不是
import android.R;
)。我确实有“import android.R;”,但我尝试了project->clean和CTRL+SHIFT+O,但没有改变它。“import android.R;”是否应该有所不同?再次感谢。@Zeldarulah那行
导入android.R
隐藏您生成的项目
R
类,android找不到布局ID。删除该行,您应该就可以了。(如果您使用了
android.R
名称空间的某些部分,那么不要导入
import android.R;
,只需在需要的地方使用
android.R.something
)好吧,这就解决了它!非常感谢。我不太清楚为什么进口会引起问题,但非常感谢。如果我能对你的答案投赞成票,我会的,但我的支持率仍然太低。