Android AutoCompleteTextView DropDown Position

后端 未结 5 1469
鱼传尺愫
鱼传尺愫 2021-01-11 11:42

I am using following code for auto complete however, dropdown items comes above the AutoCompleteTextView. I want it to show up beneath the AutoCompleteTex

相关标签:
5条回答
  • 2021-01-11 12:10

    Use the android:dropDownAnchor, android:dropDownHorizontalOffset, android:dropDownVerticalOffset and maybe others on the AutoCompleteTextView in your layout. For more info AutocompleteTextView.

    0 讨论(0)
  • 2021-01-11 12:19

    Looks like this must work:

    android:dropDownHeight="100dp"
    

    Founded here: https://stackoverflow.com/a/7648028/1723525

    Edit:

    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.

    0 讨论(0)
  • 2021-01-11 12:23

    Add dropdownheight as well as dropdownanchor, will work surely.

    android:dropDownAnchor="@id/yourIdOfViewOnTop"
    android:dropDownHeight="100dp"
    
    0 讨论(0)
  • 2021-01-11 12:24

    Set height of dropdown and set space between dropdown and edittext. Dropdown will display above and below view in dropdownanchor. Height = 200dp, dropdown will not overlap keyboard.

                    <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>
    
    0 讨论(0)
  • 2021-01-11 12:28

    Let's understand how dropdown view will be rendered. In the fact, it's PopupWindow and it decide position (above or below compare with view archor) by method findDropDownPosition. Comment of this method said that:

    Positions the popup window on screen. When the popup window is too tall to fit under the anchor, a parent scroll view is seeked and scrolled up to reclaim space. If scrolling is not possible or not enough, the popup window gets moved on top of the anchor. The results of positioning are placed in {@code outParams}.

    I've search serveral days but no any solutions really work in case you want handle dropdown's position (my case is in DialogFragment). This is my experience after serveral days, you can (cheat) code to fix this problem:

    • Use android:dropDownAnchor to set anchor of dropdown to show, it's worked but UI is seem be too strange
    • Use setDropDownVerticalOffset(offset: Int) again, it's worked but again, UI is too strange
    • Set android:dropDownHeight to higher than height of (above or below) space, result will be the same as 2 ways above
    0 讨论(0)
提交回复
热议问题