在没有 adjustPan 的情况下出现键盘时推送 Listview [英] Push Listview when keyboard appears without adjustPan

查看:23
本文介绍了在没有 adjustPan 的情况下出现键盘时推送 Listview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个带有列表视图和底部发送消息的活动.问题是当键盘显示时,不是推送底部内容,而是隐藏它.我尝试使用 adjustPan,但它会将洞视图向上推(因此无法看到列表视图的顶部元素并且操作栏也消失了).

I am trying to create an activity with a listview and a send message at bottom. The problem is that when the keyboard is shown, instead of pushing the bottom content, is just hiding it. I tried using adjustPan, but it pushes the hole view up (so there is no way to see the top elements of the listview and also de actionbar disappears).

如果你看看 WhatsApp 或 Line,其功能是当列表的最后一项显示在屏幕底部时,键盘将列表视图向上推(不取出操作栏或第一个元素屏幕),并且当列表的最后一项未显示时(向上滚动后),键盘隐藏在底部列表中(正常的 adjustResize).

If you take a look at WhatsApp or Line, the functionality is that when the last item of the list is shown at the bottom of the screen, the keyboard pushes up the listview (without taking the action bar or the first elements out of the screen), and when the last item of the list is not shown (after some scrolling up) the keyboard is hidden the bottom list (a normal adjustResize).

有人处理过这个问题吗?

Anyone dealed with this issue?

谢谢

我会尝试举一个直观的例子:

I'll try to put a visual example:

所以让我们说这个 ListView:

So lets say this the ListView:

---item 1---  
---item 2---  
---item 3---  
---item 4---  
---EditText---

editText 不是 ListView 的一部分,而是底部对齐的 LinearLayout.显示键盘时,ListView 变成这样(Item 3 和 4 被键盘隐藏):

The editText is not part of the ListView, but a LinearLayout aligned at the bottom. When keyboard is shown, the ListView becomes like this (Item 3 and 4 are hidden by Keyboard):

---item 1---  
---item 2---  
---EditText---
---Keyboard---  

我想得到的是:

---item 3---  
---item 4---  
---EditText---
---Keyboard---  

我已经尝试了 android:windowSoftInputMode="adjustPan".结果是,第 3 项和第 4 项有效地被向上推,不再被键盘隐藏.问题是它推送了列表视图,但它把它推出了屏幕,所以 actionBar 消失了,即使尝试向上滚动,我也永远看不到显示键盘的 Item 1 和 2.

I've tried the android:windowSoftInputMode="adjustPan".and the result is that effectivly item 3 and 4 are pushed up and not hidden by keyboard anymore. The problem is that it pushes the listview, but it pushes it out of the screen, so the actionBar disappears, and even if trying to scroll up, I can never see the Item 1 and 2 with the keyboard shown.

希望我解释了自己,并不容易..

Hope I explained myself, not really easy..

谢谢

推荐答案

好的,我已经为你找到了一个解决方案,你想要做的基本上是每次让 ListView 滚动到底部.您可以通过以下方式执行此操作:

Okay I have found a solution for you, what you want to do is essentially have the ListView scroll to the bottom every time. You can do this by:

ListView l = getListView();
l.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
l.setStackFromBottom(true);

如果是Activity,在onCreate中进行.如果是Fragment,则在onViewCreated中进行.

If it is an Activity, do it in onCreate. If it is a Fragment, do it in onViewCreated.

这篇关于在没有 adjustPan 的情况下出现键盘时推送 Listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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