开发者

Animate tab switch with TabHost

Hi: When the user clicks on another tab an animation should appear to the next view? What is t开发者_高级运维he best to do this?


By default, no animation is applied, at least on honeycomb. The view will just pop on.

You could do something like this if you wanted to animate it:

Find the child of the tab and play an animation on it.

Example: First set a listener:

exampleTabhost.setOnTabChangedListener(new OnTabChangeListener()
    {
        @Override
            public void onTabChanged(String tabId)
            {
                refreshTabHostUI(exampleTabhost);
            }
        });

In your listener play the animation on your tab:

View tab1 = th.findViewById(R.id.tab1);
    if( tab1 != null )
        playAnim(tab1, getBaseContext(), android.R.anim.fade_in, 500);

Play anim function:

public Animation playAnim( View v, Context con, int animationid, int startOffset )
    {
        if( v != null )
        {
            Animation animation = AnimationUtils.loadAnimation(con, animationid  );
            animation.setStartOffset(startOffset);
            v.startAnimation(animation);

            return animation;
        }
        return null;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜