<?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>
我将按钮设置在 View 底部,并将文本框设置在它们上方,但为什么所有按钮都线性显示。首先显示“搜索图像”按钮,然后显示“搜索网页”,然后显示“文本框”,但它们并不位于底部,这不是我想要的。
最佳答案
您还没有描述您想要什么...但我猜测您想要屏幕底部的布局如下:
| |
| (EditText ) |
| (Button) (Button) |
-----------------------------------------------
布局:
<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>
关于java - 在主布局上定位对象意外失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12664423/