ScrollView .scrollTo not working? Saving ScrollView position on rotation

前端 未结 7 1488
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  Happy的楠姐
    2020-12-05 02:24

    For MVVMCross:

    protected override void OnSaveInstanceState(Bundle outState)
    {
        base.OnSaveInstanceState(outState);
    
        ScrollView sv = FindViewById(Resource.Id.dispatchScrollView);
        int posY = sv.ScrollY;
    
        outState.PutInt("scrollY", posY);
    }
    
    protected override void OnRestoreInstanceState(Bundle savedInstanceState)
    {
        base.OnRestoreInstanceState(savedInstanceState);
    
        ScrollView sv = FindViewById(Resource.Id.dispatchScrollView);
        int posY = savedInstanceState.GetInt("scrollY");
    
        sv.Post(new Runnable(new Action(() => sv.ScrollTo(0, posY))));
    }
    

提交回复
热议问题