Android AutoCompleteTextView 下拉位置 [英] Android AutoCompleteTextView DropDown Position

查看:39
本文介绍了Android AutoCompleteTextView 下拉位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码进行自动完成,但是,下拉项位于 AutoCompleteTextView 上方.我希望它显示在 AutoCompleteTextView 下方.我怎样才能做到这一点?

I am using following code for auto complete however, dropdown items comes above the AutoCompleteTextView. I want it to show up beneath the AutoCompleteTextView. How can I do that?

package com.example.autocomplete;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         setContentView(R.layout.activity_main);

         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                 android.R.layout.simple_list_item_1, COUNTRIES);
         AutoCompleteTextView textView = (AutoCompleteTextView)
                 findViewById(R.id.countries_list);
         textView.setAdapter(adapter);
     }

     private static final String[] COUNTRIES = new String[] {
         "Belgium","Belgam","Bellam", "France Belgium", "Italy", "Germany", "Spain"
     };
 }

xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <AutoCompleteTextView
        android:id="@+id/countries_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp"
        android:dropDownHeight="100dp"
        android:ems="10"
        android:text="AutoCompleteTextView" >

        <requestFocus />
    </AutoCompleteTextView>

</RelativeLayout>

推荐答案

看起来这应该可行:

android:dropDownHeight="100dp"

在这里创建:https://stackoverflow.com/a/7648028/1723525

我尝试了一个新的 Activity 和如下所示的建议.也许您必须将 dropDownHeight 更改为 150dp,因为您的 marginTop 为 100dp.我猜 dropDownHeight 必须高于 Y 位置(= 填充 + 边距).让我知道它是否有效.

I tried with a new Activity and the suggestions ara shown below. Maybe you have to change the dropDownHeight to 150dp because you have marginTop of 100dp. I guess that the dropDownHeight must be higher than the Y position (= padding + margin). Let me know if it works.

这篇关于Android AutoCompleteTextView 下拉位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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