下拉菜单会忽略Android布局填充 [英] Android layout padding is ignored by dropdown

查看:85
本文介绍了下拉菜单会忽略Android布局填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以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"

忽略相对布局的填充.有任何解决方法的想法吗?

ignores the padding of the relative layout. Any ideas how to fix this?

推荐答案

已解决.我必须定义另一个仅包含自动完成文本视图和按钮的相对布局.该布局是弹出窗口的锚点,将相对布局的宽度作为自己的宽度.关键:

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"

简短版本:

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

这篇关于下拉菜单会忽略Android布局填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆