【问题标题】:Adding padding on android AutoCompleteTextView popup在 android AutoCompleteTextView 弹出窗口上添加填充
【发布时间】:2019-03-06 17:05:04
【问题描述】:

在过去的两个半小时里,我一直在尝试做一些非常简单的事情:更改 Android 的 AutoCompleteTextView 弹出窗口(显示自动完成选项的窗口)中的填充。
我正在尝试这样做,因为我的应用程序中的项目具有文本的高度(我不确定为什么),所以我想让点击变得更容易。但是我能找到的每一个想法都没有奏效。
因此,如果有人能发现这个问题或提供替代解决方案,我真的会很高兴。

为了记录,我使用的是 android studio,并且我已经删除了支持 API(因为我的最小 API 是 16),所以我的应用程序仅使用 100% 原生度假村。

【问题讨论】:

标签: android autocompletetextview


【解决方案1】:

我刚刚找到了一种方法,我必须使用已经包含项目填充的文本视图来制作自定义视图布局。比我创建了一个使用此布局的自定义适配器。

布局是这样的

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:layout_margin="0dp"
    android:paddingLeft="@dimen/thin_margin"
    android:paddingRight="@dimen/thin_margin"
    android:paddingTop="@dimen/list_1line_item_padding"
    android:paddingBottom="@dimen/list_1line_item_padding"/>

而在自定义适配器中只是在getView方法中使用了它

itemView = LayoutInflater.from(ctx).inflate(R.layout.list_1line_item, null);

【讨论】:

    【解决方案2】:
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="20dp"
    >
    
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/dp_15"
        android:paddingBottom="@dimen/dp_15"
        android:id="@+id/parentid">
    
    
        <AutoCompleteTextView
            android:id="@+id/address_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/light_gray_bg"
            android:drawableRight="@drawable/icon_search_smaller"
            android:gravity="center_vertical"
            android:hint="Start typing location"
            android:inputType="textCapWords" 
            android:popupBackground="@drawable/auto_location_popup_bg"
            android:textColor="@color/black"
            android:textColorHint="@color/dark_grey"
            android:textSize="16sp"
            android:visibility="visible"
            android:dropDownWidth="wrap_content"
            android:dropDownAnchor="@+id/parentid">/>
    
        <requestFocus />
    
    </RelativeLayout>
    
    </RelativeLayout>
    

    【讨论】:

      【解决方案3】:

      定义另一个仅包含自动完成文本视图和按钮的相对布局。看看这个链接

      Android layout padding is ignored by dropdown

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-05-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-29
        • 2022-01-05
        • 1970-01-01
        相关资源
        最近更新 更多