Android layout padding is ignored by dropdown

一笑奈何 提交于 2019-12-06 06:45:14

Solved it. I had to define another relative layout wrapping only the autocomplete textview and the button. This layout is the anchor of the popup, taking the width of the relative layout as its own width.The key:

android:dropDownWidth="wrap_content"
android:dropDownAnchor="@+id/anchor"

Short version:

<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>
//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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!