實現方式:
一、
mListView.setSelection(adapter.getCount()-1);
二、在ListView的xml添加以下屬性:
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
三:scrollView頁面嵌套listView,一開進去就顯示在最底部的listView,原因是listItem有控件獲得了焦點,
解決方法:在listView的父層加上 android:descendantFocusability="blocksDescendants";即可
可能會發生點擊每一個item的時候沒有反應,無法獲取的焦點。原因多半是由於在你自己定義的Item中存在諸如
ImageButton,Button,CheckBox等子控件(也可以說是Button或者Checkable的子類控件),此時這些子控件會將焦點獲取到,
所以常常當點擊item時變化的是子控件,item本身的點擊沒有響應。
屬性的值有三種:
beforeDescendants:viewgroup會優先其子類控件而獲取到焦點
afterDescendants:viewgroup只有當其子類控件不需要獲取焦點時才獲取焦點
blocksDescendants:viewgroup會覆蓋子類控件而直接獲得焦點
