RecyclerView行为-打开/关闭键盘时为空 [英] RecyclerView behavior - Goes empty when keyboard is opened/closed

查看:93
本文介绍了RecyclerView行为-打开/关闭键盘时为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 SearchView Filterable 实现了 RecyclerView v7 中的所有类.现在有这种令人讨厌的行为.每次抬起或关闭键盘时, RecyclerView 的内容都会变为空白.计数仍然正确,但是视图为空.我的猜测与 Layout 大小的变化有关.这是正常现象还是出问题了?怎么处理呢?我可以显示代码,但是不太清楚哪一部分是相关的,所以请告诉我可以在此处添加什么?

I have implemented a RecyclerView with SearchView and Filterable; all classes from v7. Now there is this behavior that is annoying. Whenever the keyboard is brought up or closed the contents of the RecyclerView goes blank. The count is still correct but the view is empty. My guess, it has something to do with the Layout size change. Is this behavior normal or something is wrong? How to deal with it? I can show the code but don't quite know which part will be relevant so tell me what can I add here?

推荐答案

在输入问题时,发现

While typing in the question, found this from the similar questions.

请在清单的活动中添加以下行.希望它能工作.android:windowSoftInputMode ="adjustPan"

Please add following line to your activity in manifest. Hope it works. android:windowSoftInputMode="adjustPan"

更准确地说,在 AndroidMenifest.xml activity 标签的 activity 标签中添加 android:windowSoftInputMode ="adjustPan" 打开.

More precisely, add android:windowSoftInputMode="adjustPan" in the activity tag in AndroidMenifest.xml where the keyboard is going to be opened.

示例:

<activity
        android:name=".FManagerActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustPan"
        android:theme="@style/AppTheme.Light.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

基本上,这是打开或关闭键盘时活动做出反应的行为. adjustPan 告诉键盘覆盖活动视图,而不影响其内容.否则,在打开键盘时,活动的大小也会改变,这会使内容消失,因为在隐式操作期间和之后均未调用 notifyDatasetChanged().

It is basically the behavior in which the activity reacts when the keyboard is opened or closed. adjustPan tells the keyboard to overlay the view of the activity not disturbing it's content. Without that when the keyboard is opened the size of the activity also changes which makes the content disappear as notifyDatasetChanged() is not called during and after the implicit actions.

这篇关于RecyclerView行为-打开/关闭键盘时为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆