【问题标题】:Android keyboard overlaps ListViewAndroid 键盘与 ListView 重叠
【发布时间】:2013-12-31 17:44:20
【问题描述】:

我有一个问题,我有一个 ListView 和一个这样设计的 EditText:

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".ShoutboxTab" >

    <ListView
        android:id="@+id/shoutbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/shoutbox_field"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="14dp"
        android:layout_marginRight="20dp" >
    </ListView>

    <Button
        android:id="@+id/shoutbox_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/shoutbox_field"
        android:text="Shout" />

    <EditText
        android:id="@+id/shoutbox_field"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/shoutbox_button"
        android:layout_alignLeft="@+id/shoutbox"
        android:ems="10" >

        <requestFocus />
    </EditText>

</RelativeLayout>

所以 EditText 在 ListView 下。当我将项目添加到 ListView 并单击 EditText 键入时,键盘与 ListView 的底部重叠。我想确保 ListView 的底部与键盘一起上升。这可能吗?谢谢

【问题讨论】:

    标签: android listview android-listview keyboard


    【解决方案1】:

    在您的清单中使用&lt;activity android:windowSoftInputMode="adjustResize"&gt;。 第二次在您的&lt;ListView /&gt; 中添加android:transcriptMode="alwaysScroll" 属性

    【讨论】:

      【解决方案2】:

      您使用的是&lt;activity android:windowSoftInputMode="adjustResize" ... &gt; 在你的清单中? http://developer.android.com/training/keyboard-input/visibility.html

      【讨论】:

      • 我把它放进去,没有帮助。这可能与我将片段用于选项卡视图这一事实有关吗?
      • adjustPan 应该按照这篇文章去做。developer.android.com/guide/topics/manifest/… 给出了可用选项的完整列表。
      【解决方案3】:

      我是这样解决的:

      V.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                  @Override
                  public void onGlobalLayout() {
                      int heightDiff = V.getRootView().getHeight() - V.getHeight();
                      if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                          shoutbox.setSelection(adapter.getCount() - 1);
                      }
                   }
              });
      

      V 是视图。

      可能不是最好的方法,但它是最简单的! ;)

      【讨论】:

      • 这个有效,但列表视图不再滚动。我错过了什么吗?
      【解决方案4】:

      查看您的代码,我猜这是某种警报框。如果您正在使用带有自定义对话框类的自定义对话框,请将此行添加到自定义对话框类的 onCreate() 中,此处已回答:https://stackoverflow.com/a/53150825/7451779

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-14
        • 1970-01-01
        • 1970-01-01
        • 2018-02-01
        相关资源
        最近更新 更多