日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android expandablelist 自动滚动,在ExpandableListView中,如何保留滚动位置_android_开发99编程知识库...

發(fā)布時間:2023/12/15 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android expandablelist 自动滚动,在ExpandableListView中,如何保留滚动位置_android_开发99编程知识库... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在一些實(shí)驗(yàn)之后我做了一個滿意的解決,它還保留了很好的滾動位置頂部可見項(xiàng)。

事實(shí)上,三種不同部分的信息需要保存和恢復(fù): 狀態(tài)( e .g列表。 其中組被展開),第一個可見項(xiàng)的索引和優(yōu)良滾動位置。

不幸的是,似乎只有第一個保存由onSaveInstanceState可展開列表視圖的方法,所以其他兩個需要單獨(dú)存儲。 這不同于非可展開列表視圖,其中,看來在onSaveInstanceState方法保存所需要的所有信息正確的恢復(fù)狀態(tài)和位置列表( 對于這個主題,參看 Scroll到中的某一位置listView ) 。?

下面是代碼段,之上ExpandableListActivity派生類:private static final String LIST_STATE_KEY = "listState";

private static final String LIST_POSITION_KEY = "listPosition";

private static final String ITEM_POSITION_KEY = "itemPosition";

private Parcelable mListState = null;

private int mListPosition = 0;

private int mItemPosition = 0;

然后,一些繼承自:protected void onRestoreInstanceState(Bundle state) {

super.onRestoreInstanceState(state);

// Retrieve list state and list/item positions

mListState = state.getParcelable(LIST_STATE_KEY);

mListPosition = state.getInt(LIST_POSITION_KEY);

mItemPosition = state.getInt(ITEM_POSITION_KEY);

}

protected void onResume() {

super.onResume();

// Load data from DB and put it onto the list

loadData();

// Restore list state and list/item positions

ExpandableListView listView = getExpandableListView();

if (mListState != null)

listView.onRestoreInstanceState(mListState);

listView.setSelectionFromTop(mListPosition, mItemPosition);

}

protected void onSaveInstanceState(Bundle state) {

super.onSaveInstanceState(state);

// Save list state

ExpandableListView listView = getExpandableListView();

mListState = listView.onSaveInstanceState();

state.putParcelable(LIST_STATE_KEY, mListState);

// Save position of first visible item

mListPosition = listView.getFirstVisiblePosition();

state.putInt(LIST_POSITION_KEY, mListPosition);

// Save scroll position of item

View itemView = listView.getChildAt(0);

mItemPosition = itemView == null ? 0 : itemView.getTop();

state.putInt(ITEM_POSITION_KEY, mItemPosition);

}

它也能在我Froyo設(shè)備。

總結(jié)

以上是生活随笔為你收集整理的android expandablelist 自动滚动,在ExpandableListView中,如何保留滚动位置_android_开发99编程知识库...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。