简体   繁体   English

Android autocompletetextview建议下拉列表显示在软键盘下方

[英]Android autocompletetextview suggestions drop down appear below soft keyboard

I have a AutoCompleteTextView set up at the bottom of the screen, below a map fragment. 我在屏幕底部的地图片段下方设置了AutoCompleteTextView。 The soft keyboard push both of them up when it appears. 出现时,软键盘将它们向上推。 The suggestions layout doesn't seem to detect the keyboard however, and expands downwards, hiding all the suggestions. 建议布局似乎无法检测到键盘,但会向下扩展,隐藏所有建议。

I know this question has been asked here some times, but all of the solutions seems out of date, as none of them remedy the problem. 我知道这里已经有人问过这个问题了,但是所有解决方案似乎都过时了,因为它们都不能解决问题。 I've also tried various R.layout.x, but none of them seem to detect the keyboard. 我也尝试过各种R.layout.x,但似乎没有一个能检测到键盘。

Here is the xml: 这是xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">



    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        tools:context=".MapsActivity" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <AutoCompleteTextView
            android:id="@+id/auto_complete_search_map"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/hint_search"/>

        <Button
            android:id="@+id/search_in_map"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/search" />

    </LinearLayout>


</LinearLayout>

And here is the activity: 这是活动:

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_view);

        search = findViewById(R.id.search_in_map);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.select_dialog_multichoice, PLACE_TYPES);
        user_input = findViewById(R.id.auto_complete_search_map);
        user_input.setAdapter(adapter);
    }

Is there anyway to simply force the list to expand up instead of down? 无论如何,有没有简单地迫使列表扩大而不是缩小? If not, what are some other viable means to fix this? 如果没有,还有什么其他可行的方法来解决此问题? Placing the AutoCompleteTextView at the top would fix this, but that wouldn't be optimal considering this is the main feature of this activity and should be easily reachable on the screen. 将AutoCompleteTextView放在顶部可以解决此问题,但是考虑到这是此活动的主要功能,因此并不是最佳选择,并且应该可以在屏幕上轻松访问。

Thanks for any replies! 感谢您的任何答复!

AutoCompleteTextView decides to open down or up based on available space: if it has more space up it will expand up and if it has more space down it will expand down. AutoCompleteTextView决定根据可用空间打开或向上打开:如果它有更多的空间,它会向上扩展;如果它有更多的空间,它会向下扩展。 All you have to do is to adjust your layout in sort that the AutoCompleteTextView expands on the desired direction. 您要做的就是调整布局,使AutoCompleteTextView沿所需方向扩展。

Try wrapping all the layout inside a ScrollView element. 尝试将所有布局包装在ScrollView元素内。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent">
    <LinearLayout  
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content">
             ...

If I'm not wrong I did it time ago in a log in screen and the keyboard uses the ScrollView so that the content should not be hidden. 如果我没记错的话,我是在不久前在登录屏幕上进行操作的,并且键盘使用了ScrollView因此不应隐藏内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM