ScrollView .scrollTo not working? Saving ScrollView position on rotation

前端 未结 7 1487
没有蜡笔的小新
没有蜡笔的小新 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());
      }
    });
    
    0 讨论(0)
提交回复
热议问题