Android AutoCompleteTextView DropDown Position

后端 未结 5 1505
鱼传尺愫
鱼传尺愫 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条回答
  •  猫巷女王i
    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

提交回复
热议问题