Android AutoCompleteTextView DropDown Position

I use the following code to autocomplete, however the dropdowns are located above AutoCompleteTextView. I want it displayed under AutoCompleteTextView. How can i do this?

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>
+6
source share
5 answers

Seems like this should work:

android:dropDownHeight="100dp"

Based here: fooobar.com/questions/306039 / ...

Edit:

I tried the new activities and suggestions shown below. Perhaps you need to change dropDownHeight to 150dp because you have a marginTop of 100dp. I think dropDownHeight should be higher than the Y position (= padding + margin). Let me know if this works.

+8

edittext. . = 200 , .

                <RelativeLayout
                    android:id="@+id/dropdownAutoCompleteTextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp">
                    <AutoCompleteTextView
                        android:id="@+id/autoTextViewState"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:digits="@string/get_started_petname_digits"
                        android:dropDownAnchor="@+id/dropdownAutoCompleteTextView"
                        android:dropDownHeight="200dp"
                        android:hint="Colorado"
                        android:imeOptions="actionNext"
                        android:inputType="textEmailAddress|textCapWords"
                        android:maxLength="15"
                        android:nextFocusDown="@+id/editZipCode"/>
                </RelativeLayout>
+6

android:dropDownAnchor, android:dropDownHorizontalOffset, android:dropDownVerticalOffset , , AutoCompleteTextView . AutocompleteTextView.

+2

dropdownheight, dropdownanchor, .

android:dropDownAnchor="@id/yourIdOfViewOnTop"
android:dropDownHeight="100dp"
0

, . , PopupWindow ( view archor) findDropDownPosition. , :

. , , , . , . {@code outParams}.

, , ( DialogFragment). , () , :

  • android:dropDownAnchor android:dropDownAnchor , ,
  • setDropDownVerticalOffset(offset: Int) , , ,
  • android:dropDownHeight , ( ) , ,
0

Source: https://habr.com/ru/post/1657268/


All Articles