It is a shame that the first essay on the procedure is a question that I cannot solve and explain in the first place, and then I will make a note of it and then add it later.
Recently in the making of an Android Imapp, the protocol uses the XMPP (because the time is tight, and belongs to the internal software, basics), the server with the OpenFire two times development, the Android side is naturally asmack, there are many examples on the internet, The package is already in place.
In the process of doing this, the chat page must have been using the ListView. Approximate effects such as:
Sorry, ah, this is imitation of ...
Everyone used to know that when you enter the chat interface, the ListView automatically scrolls to the latest message, which is the last line.
It seems that this effect should be done well because the ListView has many ways to do this.
But... But... Here's the problem.
My practice is to
1. First set up in XML
Android:transcriptmode= "Alwaysscroll"
The explanation for this property on the Web is that you can automatically slide the last line to the viewable range when the list changes.
Attention is ... change the time ... This means that if a new data is added, or if the size of the ListView changes (that is, when the keyboard pops up when you click EditView), the auto-scrolling effect will appear.
This does not include the initial loading of data, at least my real machine here is no effect, on the above I said the phenomenon is my personal testing phenomenon, there is no universal authority to speak of.
Continue to check Baidu, some people say to add a sentence
Android:stackfrombottom= "true"
I added, it is really effective, but there is a problem: if the data volume of the ListView can exceed a screen, the effect is satisfied, if the amount of data is less than a screen will appear the following effect:
Then I'll consider using the data volume in the ListView to dynamically set this property
if (...) { Lv.setstackfrombottom (true); The default is False}
I thought it would be all right. Yes, if it is plain text really no problem, but if there is a picture that needs to be loaded asynchronously ... Here comes the question again ... I use the open source component Imageloader
String MapURL = Scheme.FILE.wrap (Data.getpath ()), Imageloader.getinstance (). DisplayImage (MapURL, Content_img, options);
Once a picture needs to be loaded, the ListView will display the first data ... Baidu ... Check the SetSelection (position) method of the ListView. My idea is to manually select the last line after setting up the adapter:
Listview.setadapter (adapter); Listview.setselection (Adapter.getcount ()-1);
Then the phenomenon is very strange, when the activity first OnCreate, the scroll bar is not the most and not the bottom, in the middle of a position, and then return to the key, again enter, is the bottom of the ...
The first time into the obvious scroll bar in the middle position, above the first show not fully return the key, again into all normal
I think the reason is the first time because the image is loaded asynchronously when the UI is manipulated, causing setselected () to fail, the second normal may be Imagloader has the cache, and the picture is not loaded ...
I really can't do it. I'll wait until the picture is loaded and then setselected ().
imageloader.getinstance (). DisplayImage (ImageUrl, content_img, Options, new Simpleimageloadinglistener () { @Override publicvoid onloadingcomplete (String Imageuri, view view, Bitmap loadedimage) { superonloadingcomplete (Imageuri, view, Loadedimage); Chatlistadapter. this. Listview.setselection (GetCount ()-1); });
This is the head of the row ... There is still a problem ... This kind of writing in the list sliding process if the picture is loaded, there will be a jump card effect. So finally, I want to judge and set the first time to enter the interface when loading the picture successfully executed the above code ... And then you don't do it.
Tell me why it's so complicated!!! I'm not afraid of your jokes when I post the process. For advice!!!
[Android] using the listview to do IM chat problems