【问题标题】:Selection list cut off in AutoCompleteTextView in Dialog对话框中 AutoCompleteTextView 中的选择列表被截断
【发布时间】:2020-05-17 03:59:23
【问题描述】:

我有一个对话窗口,它覆盖了整个屏幕高度的 1/3,并显示在我的活动顶部。该对话框包含两个 AutoCompleteTextView 字段。

我面临的问题是,当用户开始在 AutoCompleteTextView 中输入内容时,包含所有建议的列表仅显示到对话框的底部,但即使列表更长也不会超出此范围。它看起来像被切断了。 (截图左)

只有在我长按建议列表中的一个项目后,该列表才会全长显示。 (右图)

截图在:http://img704.imageshack.us/i/dialogdropdown.png/ screenshot http://img704.imageshack.us/img704/1893/dialogdropdown.png

如何解决此问题,以便在用户开始输入内容时列表从头开始显示完整长度?

代码方面没有什么特别的,我所做的就是:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getContext(), R.layout.nav_route_autocomplete_row, locStrings);        
AutoCompleteTextView txtStartPos = (AutoCompleteTextView) findViewById(R.id.txtStartPos);
txtStartPos.setAdapter(adapter);
...

一种解决方法的想法是以某种方式调度一个运动事件来模拟一个触摸(但随后不选择)列表项之一。任何解决方案的代码中的具体想法,有人吗?

【问题讨论】:

    标签: android


    【解决方案1】:

    现在我假设这是一个错误,我已经在这里提交了:http://code.google.com/p/android/issues/detail?id=9917

    但如果有人知道这个问题的解决方案,我将不胜感激,并很乐意用它来换取一些赏金。

    编辑:

    现在我想到的一种解决方法是将对话框扩展到屏幕的最底部,但背景保持透明,因此它看起来与现在相同,但实际上具有不会切断列表的高度.我会试一试...

    【讨论】:

      【解决方案2】:

      不久前我遇到了这个问题。我与AutoCompleteTextView 进行了小对话,下拉列表中有 10 多个项目。这份名单被剪掉了。我的解决方案是:
      在我的对话框布局文件中放置一些空的View 参数

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical">
      <!--
      Some Views placed here
      -->
             <View
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:visibility="invisible" />
      
      </LinearLayout>
      

      它使我的小对话框像一个全屏对话框,但实际上没有显示“尾巴”,而且我的 DropDown 根本没有被剪切,因为它有足够的位置显示来自 DropDown 的列表项。

      【讨论】:

        【解决方案3】:
        if (yourlist.size() > 5) {
            yourtextview.setDropDownHeight(562);
        } else {
            yourtextview.setDropDownHeight(anytextview.getHeight() * yourlist.size());
        }
        
        //Workaround ->  Write this condition under on click and on focus change of your autocomplete text view 
        

        【讨论】:

          【解决方案4】:

          只是在黑暗中拍摄,但您是否尝试在 Activity 顶部的对话框视图上将 android:clipChildren 设置为 false

          【讨论】:

          • 我尝试为我的对话框布局的最外层 LinearLayout 设置该属性,以及 AutoCompleteTextView 是其(子)子项的所有其他属性。但这无济于事。既然是对话框,应该更像是window.setClipChildren(false),可惜window没有这样的方法。或一些标志,如 window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);但这一切都无济于事。
          【解决方案5】:

          我已经成功实现了这一点,但它并不漂亮。

          我最终覆盖了我的SimpleCursorAdapter.newView() 方法,沿着ViewParent 层次结构向上移动,直到到达根View,然后通过在FLAG_LAYOUT_NO_LIMITS 标志中进行ORing 来修改它的WindowManager.LayoutParams

          每次显示下拉菜单时都需要重做。

          【讨论】:

            【解决方案6】:

            如此处所示:Scrolling drop-down-menu over the keyboard in autocompletetextview

            您可以使用 AutoCompleteTextView 的属性 android:dropDownHeight 来强制它达到一定高度。这并不能真正解决问题,但这是我能找到的最好的。

            注意:只有在对话框中使用 AutoCompleteTextView 时才会出现此问题。当它用于活动或片段的布局时,它就可以正常工作。

            从姜饼到果冻豆,这个问题一直存在。

            【讨论】:

              猜你喜欢
              • 2012-07-23
              • 2020-09-23
              • 2021-10-12
              • 1970-01-01
              • 2016-07-30
              • 1970-01-01
              • 2019-05-27
              • 1970-01-01
              • 2015-04-29
              相关资源
              最近更新 更多