Sencha Touch - scroll to last tab on TabBar

怎甘沉沦 提交于 2019-12-06 06:44:03

问题


There is a view with many tabs in my App. I'd like to set focus on the last one. I can set active tab this.setActiveItem(10), but I'm not able to scroll (programmatically) tabbar to the last item. Content of the 10th tab is shown but 10th item on tabbar is hidden, so user could be confused.

Thanks a lot in advance.


回答1:


A really good question and many people may find this useful.

So first, instance of tabBar is needed so we can get activeTab of tabPanel. Then we can easily get the offset of tab item. Here, tab item means not the container that holds tab's contents but the tab indicator which can either is placed at top or bottom. So we just need offset of active tab item from tabBar not the container.

    this.getMyTabPanel().setActiveItem(6);

    var tabBar = this.getMyTabPanel().getTabBar();

    var activeTab = tabBar.getActiveTab();
    var x= activeTab.element.getX();
    var y = activeTab.element.getY();

Next part is, to get instance of tabBar scroller. Once we get this we can pragmatically scroll it do desired position we get in above step.

    var scroller = this.getMyTabPanel().getTabBar().getScrollable().getScroller();

    scroller.scrollTo(x,y);

Working demo is here


update

You can also enable animation while pragmatically scrolling with -

scroller.scrollTo(x, y, true);


来源:https://stackoverflow.com/questions/16685963/sencha-touch-scroll-to-last-tab-on-tabbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!