ScrollView .scrollTo not working? Saving ScrollView position on rotation

前端 未结 7 1490
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 02:18

Ok.. I must be overlooking something real simple here, but i think i\'m trying to do something fairly basic.. Simply retain the scrollbar position of a ScrollView on orienta

7条回答
  •  鱼传尺愫
    2020-12-05 02:24

    onRestoreInstanceState() is just to early to scroll the view. That's why posting new Runnable helps, but not always. Sometimes one even have to use postDelayed() to let it work. For Fragment one can use onViewCreated() instead :

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        sViewX = savedInstanceState.getInt("sViewX");   
        sViewY = savedInstanceState.getInt("sViewY");
        sView.scrollTo(sViewX, sViewY);
    }
    

提交回复
热议问题