Save the position of scrollview when the orientation changes

后端 未结 6 1665
星月不相逢
星月不相逢 2020-12-02 23:57

These is my layout:

\"detail

I need to save the scrolling position when the orientation change

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 00:29

    Just set android:id on your scrolling element. Your view will save its scrolling position automatically.

    Code from View.java:15554

    protected void dispatchSaveInstanceState(SparseArray container) {
        if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) {
            mPrivateFlags &= ~PFLAG_SAVE_STATE_CALLED;
            Parcelable state = onSaveInstanceState();
            if ((mPrivateFlags & PFLAG_SAVE_STATE_CALLED) == 0) {
                throw new IllegalStateException(
                        "Derived class did not call super.onSaveInstanceState()");
            }
            if (state != null) {
                // Log.i("View", "Freezing #" + Integer.toHexString(mID)
                // + ": " + state);
                container.put(mID, state);
            }
        }
    }
    

提交回复
热议问题