【问题标题】:Android: Recyclerview not resizing when softinput keyboard appearsAndroid:出现软输入键盘时,Recyclerview 未调整大小
【发布时间】:2015-11-04 23:49:06
【问题描述】:

我有一个包含片段的活动,并且该片段包含一个自定义视图。 customview 包含一个edittext,在它的正下方是一个高度为match_parent 的recyclerview。当用户关注edittext时,会出现一个软输入键盘。不幸的是,这个键盘隐藏了它下面的一半recyclerview。我希望 recyclerview 调整到屏幕的剩余可见高度(在编辑文本下),以便列表中的项目不会被键盘隐藏。

我尝试为清单中的活动设置adjustresize,但没有效果:

android:windowSoftInputMode="adjustResize"

我尝试将我的应用主题设置为基本主题(以防我的自定义主题中的某些内容导致问题) - 无效:

android:theme="@style/Theme.AppCompat.NoActionBar"

我已经检查以确保层次结构中的任何地方都没有框架布局到必须调整大小的视图(我读了一个 SO 线程,它可能是一个问题) - 没有。

我检查了活动、片段、自定义视图和连接的每个适配器,以确保我没有在任何地方调用 getWindow(我没有)。

自定义视图在运行时从视图桶中膨胀。这有联系吗?

编辑:

父级的内容:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parent_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
...


    <ViewStub
        android:id="@+id/viewstub_outername"
        android:layout="@layout/viewstub_thatIneed"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</RelativeLayout>

viewstub 的内容:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/viewstub_root"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:background="@android:color/white"
    >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp"
        android:visibility="invisible"
        />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp"
        android:visibility="invisible"
        />

</RelativeLayout>

这样显示键盘:

public static void showSoftKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}

【问题讨论】:

  • 请贴出演示问题的代码sn-p。
  • @GaneshKumar 查看我的编辑
  • 嘿@Jon,你找到解决这个问题的方法了吗?请指导我如何修复它?
  • 我也面临同样的问题

标签: java android user-interface android-recyclerview


【解决方案1】:

不要在清单文件中做任何事情。只需使用

((LinearLayoutManager)recyclerView.getLayoutManager()).setStackFromEnd(true);

这将负责 recyclerview 调整大小。

【讨论】:

  • 您的解决方案解决了我的问题,其他解决方案没有解决我的问题。谢谢!
  • 惊人的解决方案。尝试了ADJUST_RESIZEHIDDEN 等但失败了,这个可以节省一天的时间。 Android 总是让我大吃一惊,哈哈:D
  • 你是我的上帝。谢谢!
  • 当顶部有编辑文本时,这会弄乱 recycelrview。 recylerview 确实滚动,但视图不可见
猜你喜欢
  • 2011-10-09
  • 2011-07-15
  • 2017-07-25
  • 1970-01-01
  • 1970-01-01
  • 2015-08-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多