as xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="20dp">
<Button
android:id="@+id/locationButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:minWidth="46dip"
android:onClick="getLocation"
android:text="@string/icon_map_marker" />
<AutoCompleteTextView
android:id="@+id/autocomplete_city"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="@string/city_hint"
android:inputType="text"
android:layout_alignBottom="@+id/locationButton"
android:layout_alignTop="@id/locationButton"
android:layout_toLeftOf="@id/locationButton"
android:dropDownWidth="match_parent"
/>
<requestFocus />
</RelativeLayout>
正如您所见
android:dropDownWidth="match_parent"
忽略相对布局的填充。任何想法如何解决这个问题?
答案 0 :(得分:7)
解决了它。我不得不定义另一个相对布局,只包含自动完成文本视图和按钮。此布局是弹出窗口的锚点,将相对布局的宽度作为自己的宽度。键:
android:dropDownWidth="wrap_content"
android:dropDownAnchor="@+id/anchor"
简短版本:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="20dp" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/anchor" >
<Button
android:id="@+id/locationButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
<AutoCompleteTextView
android:id="@+id/autocomplete_city"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/locationButton"
android:layout_alignTop="@id/locationButton"
android:layout_centerHorizontal="true"
android:layout_toLeftOf="@id/locationButton"
android:dropDownWidth="wrap_content"
android:hint="@string/city_hint"
android:dropDownAnchor="@+id/anchor" />
<requestFocus />
</RelativeLayout>
</RelativeLayout>
答案 1 :(得分:0)
//try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<AutoCompleteTextView
android:id="@+id/autocomplete_city"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="city_hint"
android:inputType="text"
android:dropDownWidth="match_parent"/>
<Button
android:id="@+id/locationButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="46dip"
android:onClick="getLocation"
android:text="icon_map_marker" />
</LinearLayout>