Java 在主布局上定位对象意外失败
我将按钮设置在视图的底部,并将文本框设置在其上方,但为什么所有按钮都线性显示。首先显示按钮搜索图像,然后是搜索网页,然后是文本框,它们不在底部,这不是我想要的 在第二个按钮中,将按钮的id更改为+@id/imgbtn1,这样它就不会与第一个按钮冲突 将android:layout\u alignBottom=@id/imgbtn更改为android:layout\u alignParentBottom=trueJava 在主布局上定位对象意外失败,java,android,xml,Java,Android,Xml,我将按钮设置在视图的底部,并将文本框设置在其上方,但为什么所有按钮都线性显示。首先显示按钮搜索图像,然后是搜索网页,然后是文本框,它们不在底部,这不是我想要的 在第二个按钮中,将按钮的id更改为+@id/imgbtn1,这样它就不会与第一个按钮冲突 将android:layout\u alignBottom=@id/imgbtn更改为android:layout\u alignParentBottom=true 您希望编辑文本位于何处?如果您的视图父亲是LinearLayout android:
您希望编辑文本位于何处?如果您的视图父亲是LinearLayout android:layout\u alignParentBottom=true没有任何意义。。。 您需要将“线性”更改为“相对” 如果您希望编辑文本位于按钮上方,请提供:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/bkgrndclr">
<Button
android="@+id/imgbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search Images"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
<Button
android="@id/imgbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search Web"
android:layout_alignBottom="@id/imgbtn"
android:layout_toLeftOf="@id/imgbtn" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/imgbtn"
android:layout_alignRight="@id/imgbtn" />
</LinearLayout>
给你的按钮提供不同的ID!并将它们都更改为alignParentBottom您还没有描述您想要什么。。。但我猜你希望屏幕底部有这样的布局:
android:layout_above="@id/imgbtn"
布局:
| |
| (EditText ) |
| (Button) (Button) |
-----------------------------------------------
将LinearLayout更改为RelativeLayout但有一个按钮消失,文本框向上移动到视图顶部谢谢Tamir,我希望它位于两个按钮上方,但应位于底部哦,是的,将android=@+id/imgbtn更改为android:id=@+id/imgbtn和其他id当然:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bkgrndclr"
>
<Button
android:id="@+id/btnImages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Search Images"
/>
<Button
android:id="@+id/btnWeb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/btnImages"
android:text="Search Web"
/>
<EditText
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btnImages"
android:inputType="text"
/>
</RelativeLayout>