0

我想将这些输入对齐,使其右侧有两个自动完成框,右侧有一个较小的按钮。但是,我最终得到了一个涵盖所有内容的大型自动完成功能(第二个)。

    <RelativeLayout
        android:layout_alignParentBottom="true" 
        android:id="@+id/transport_search"
        android:background="@color/dark_grey"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">

        <AutoCompleteTextView
            android:id="@+id/transport_autoCompleteFrom"
            android:layout_width="fill_parent"
            android:layout_weight="5"
            ></AutoCompleteTextView>

        <Button
            android:id="@+id/transport_switchDirection"
            android:layout_toRightOf="@+id/transport_autoCompleteFrom"
            android:layout_width="fill_parent"
            android:layout_weight="1"
            ></Button>

        <AutoCompleteTextView
            android:id="@+id/transport_autoCompleteTo"
            android:layout_width="fill_parent"
            android:layout_weight="5"
            ></AutoCompleteTextView>

        <Button
            android:id="@+id/transport_go"
            android:layout_toRightOf="@+id/transport_autoCompleteTo"
            android:layout_width="fill_parent"
            android:layout_weight="1"
            ></Button>

    </RelativeLayout>

我究竟做错了什么?

4

2 回答 2

0

您可以在 RelativeLayout 中使用 LinearLayout。下面显示了两个按钮:

    <LinearLayout android:id="@+id/buttons" android:layout_below="@id/aboveControl1"
    android:layout_width="fill_parent"  android:layout_height="wrap_content" 
    android:orientation="horizontal" android:weightSum="2" 
    android:layout_alignLeft="@id/otherControl1" android:layout_alignRight="@id/otherControl2" >
    <Button android:id="@+id/button10" android:layout_width="fill_parent" 
        android:layout_height="wrap_content" android:text="Ok" android:layout_weight="1" />
    <Button android:id="@+id/button11" android:layout_width="fill_parent" 
        android:layout_height="wrap_content" android:text="Cancel" android:layout_weight="1" />
</LinearLayout>
于 2011-05-05T03:13:52.867 回答
0

如果您更喜欢使用RelativeLayout,也许以下内容可以让您更接近您想要实现的目标。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_alignParentBottom="true"
    android:id="@+id/transport_search"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent">
    <AutoCompleteTextView
        android:id="@+id/transport_autoCompleteFrom"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="auto 1" />
    <Button
        android:id="@+id/transport_switchDirection"
        android:layout_toRightOf="@id/transport_autoCompleteFrom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button1" />
    <AutoCompleteTextView
        android:id="@+id/transport_autoCompleteTo"
        android:layout_below="@id/transport_autoCompleteFrom"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="auto 2" />
    <Button
        android:id="@+id/transport_go"
        android:layout_toRightOf="@id/transport_autoCompleteTo"
        android:layout_below="@id/transport_switchDirection"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button2" />
</RelativeLayout>

以下是此布局的屏幕截图。

此外,您可能想看看 TableLayout 如何用于Android 创建对齐字段布局中的类似结果

于 2011-05-05T03:20:26.883 回答