ScrollView .scrollTo not working? Saving ScrollView position on rotation

前端 未结 7 1489
没有蜡笔的小新
没有蜡笔的小新 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:40

    this code worked for me for dynamically scrolling tabs, maybe it will be useful for u

    TabHost tabHost;
    int currentActiveTab;
    HorizontalScrollView tabsHorizontalScrollView;
    //some code ...
    tabHost = getTabHost();
    tabsHorizontalScrollView = findViewById(R.id.tabsHorizontalScrollView);
    currentActiveTab = 8;
    //some code ...
    tabHost.setCurrentTab(currentActiveTab);
    tabHost.getTabWidget().getChildAt(currentActiveTab).post(new Runnable() {
      @Override
      public void run() {
        tabsHorizontalScrollView.scrollTo(tabHost.getTabWidget().getChildAt(currentActiveTab).getLeft(), tabsHorizontalScrollView.getScrollY());
      }
    });
    

提交回复
热议问题