[英]How to bring selected list item position in centre of listview in android
如何在android中的lisview的中心位置使選定的列表項位置我需要使用此方法public void smoothScrollByOffset(int offset)
如何找到偏移量?
我認為您真正想要的是:
smoothScrollToPositionFromTop (int position, int offset)
這將滾動顯示您指定的帶有position
的列表項,使其在ListView
頂部邊緣下方offset
像素。
要使其滾動到中心,您可以執行以下操作:
int listViewHeight = myListView.getMeasuredHeight();
myListView.smoothScrollToPositionFromTop(myItemPosition, (listViewHeight / 2));
這會將所選項目的頂部邊緣放在ListView
中間。
如果您想走得更遠,還可以獲取所測量項目視圖的高度,並從偏移量中減去一半。 這將使該項目真正“ 居中 ”在ListView
的中間高度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.