java - 在主布局上定位对象意外失败

标签 java android xml

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

相关文章:

java - 在 map 中使用泛型和对象的类

java - 我的数据无法上传到 mysql 服务器数据库显示字符串无法转换为 JSONobject

java - 线程安全的枚举单例

java - JAXB2.0 -XJC编译问题

sql - PostgreSQL 可以从函数返回的数组中选择吗?

Linux 上的 Java 程序关闭

java - 带有 RecyclerView 和 CollapsingToolbarLayout 的 CoordinatorLayout

java - 确定 Android 手机 CPU 时钟频率的最可靠方法是什么?

android - Qt API 获取应用程序用户数据在 iOS 和 Android 上的保存位置

c# - 读取、修改和写入 XML 的最佳方式