Android Question TabHost and StdViewPager doubts

Discussion in 'Android Questions' started by Jerez, Jul 19, 2015.

  1. Jerez

    Jerez Active Member Licensed User

    Hi:

    I have 3 questions:

    I need to load about 10 pages (and maybe more) in a TabHost or StdViewPager.

    1) Can i change the current tab calling it by name and not by index?
    2) When a tab is changed can i apply a slide animation? (like StdViewPager)
    3) Can i load in a StdViewPager 10 panels but only show upto 5 (touch scroll) and the others call it by code?

    thanks!
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    1) You can use a Map for this. The keys will be the tab names and the values will be the indices.
    2) Not with TabHost.
    3) You can choose to add only five panels to StdActionBar and add more panels to StdViewPager. However the user will still be able to reach the other pages with a swipe gesture.
     
  3. Jerez

    Jerez Active Member Licensed User

    Thanks Erel.
     
  4. Jerez

    Jerez Active Member Licensed User

    Maybe this code found in Stackoverflow can help to have a TabHost with transition animation? any way to wrap to use it?

    http://stackoverflow.com/questions/10009155/android-tabactivity-with-transition-animation

    Code:
    getTabHost().setOnTabChangedListener(new OnTabChangeListener() {
         
    public void onTabChanged(String tabId)
         {
                
    View currentView = getTabHost().getCurrentView();
                
    if (getTabHost().getCurrentTab() > currentTab)
                {
                    currentView.setAnimation( inFromRightAnimation() );
                
    }
                else
                {
                    currentView.setAnimation( outToRightAnimation() );
                }

                currentTab = getTabHost().getCurrentTab();
         }
    });
    Code:
    public Animation inFromRightAnimation()
    {
        
    Animation inFromRight = new TranslateAnimation(
                
    Animation.RELATIVE_TO_PARENT, +1.0f,
                
    Animation.RELATIVE_TO_PARENT, 0.0f,
                
    Animation.RELATIVE_TO_PARENT, 0.0f,
                
    Animation.RELATIVE_TO_PARENT, 0.0f);
        inFromRight.setDuration(
    240);
        inFromRight.setInterpolator(new AccelerateInterpolator());
        
    return inFromRight;
    }

    public Animation outToRightAnimation()
    {
        Animation outtoLeft = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, -1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        outtoLeft.setDuration(240);
        outtoLeft.setInterpolator(new AccelerateInterpolator());
        return outtoLeft;
    }
     
Loading...