Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

android - Push Listview when keyboard appears without 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).

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?

thanks

EDIT:

I'll try to put a visual example:

So lets say this the ListView:

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

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---  

and what I would like to get is:

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

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..

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...