ListView數據更新后,自動滾動到底部(聊天時常用)| Listview Scroll to the end of the list after updating the list


轉:http://www.cnblogs.com/bjshsqlt/p/3311830.html

If you would like to after you have updated by listAdapter, you want to make sure that the list is scrolled all the way to the bottom,

so that it displays the last element entered in the list. You  can  do this .

 

Method1:

mListView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);

Method2:

set this attribute in XML

android:transcriptMode="alwaysScroll"

Method3:

if the above two methods fail, you can try this:

you can manually tell the list to scroll to the bottom by setting the list selection to the last row.

private void scrollMyListViewToBottom() {
    myListView.post(new Runnable() {
        @Override
        public void run() {
            // Select the last row so it will scroll into view...
            myListView.setSelection(myListAdapter.getCount() - 1);
        }
    });
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM