问题描述
- TabHost滑动效果怎么实现?
-
我需要弄几个分页,就是TabHost的形式的。但是在切换选项页面的时候TabHost标签栏中的标签与标签的切换带有滑动的动画效果,最好是页面也有滑动效果。我想知道这样的效果是怎么做的?用Tabhost?ActivityGround?还是其他什么方法?要怎么实现?最好有demo可以看一下,谢谢
解决方案
用ViewPager,用Eclipse里ADT的向导就能做出来,当然不是基于TabHost的,是基于ActionBar的,不过原理是一样的。
解决方案二:
看这里http://blog.csdn.net/z13759561330/article/details/20493675
解决方案三:
看这里http://blog.csdn.net/z13759561330/article/details/20493675
解决方案四:
看这里http://blog.csdn.net/z13759561330/article/details/20493675
解决方案五:
试试这段代码:
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
/**
* A custom OnTabChangeListener that uses the TabHost its related to to fetch information about the current and previous
* tabs. It uses this information to perform some custom animations that slide the tabs in and out from left and right.
*
* @author Daniel Kvist
*
*/
public class AnimatedTabHostListener implements OnTabChangeListener
{
private static final int ANIMATION_TIME = 240;
private TabHost tabHost;
private View previousView;
private View currentView;
private int currentTab;
/**
* Constructor that takes the TabHost as a parameter and sets previousView to the currentView at instantiation
*
* @param tabHost
*/
public AnimatedTabHostListener(TabHost tabHost)
{
this.tabHost = tabHost;
this.previousView = tabHost.getCurrentView();
}
/**
* When tabs change we fetch the current view that we are animating to and animate it and the previous view in the
* appropriate directions.
*/
@Override
public void onTabChanged(String tabId)
{
currentView = tabHost.getCurrentView();
if (tabHost.getCurrentTab() > currentTab)
{
previousView.setAnimation(outToLeftAnimation());
currentView.setAnimation(inFromRightAnimation());
}
else
{
previousView.setAnimation(outToRightAnimation());
currentView.setAnimation(inFromLeftAnimation());
}
previousView = currentView;
currentTab = tabHost.getCurrentTab();
}
/**
* Custom animation that animates in from right
*
* @return Animation the Animation object
*/
private 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);
return setProperties(inFromRight);
}
/**
* Custom animation that animates out to the right
*
* @return Animation the Animation object
*/
private Animation outToRightAnimation()
{
Animation outToRight = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
return setProperties(outToRight);
}
/**
* Custom animation that animates in from left
*
* @return Animation the Animation object
*/
private Animation inFromLeftAnimation()
{
Animation inFromLeft = 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);
return setProperties(inFromLeft);
}
/**
* Custom animation that animates out to the left
*
* @return Animation the Animation object
*/
private Animation outToLeftAnimation()
{
Animation outtoLeft = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
return setProperties(outtoLeft);
}
/**
* Helper method that sets some common properties
* @param animation the animation to give common properties
* @return the animation with common properties
*/
private Animation setProperties(Animation animation)
{
animation.setDuration(ANIMATION_TIME);
animation.setInterpolator(new AccelerateInterpolator());
return animation;
}
}
解决方案六:
你可以通过使用 ViewPager和 PageIndicator 来实现。
为和旧的Android版本兼容,或者有更多其它选择。使用ViewPagerIndicator。请参考:https://github.com/JakeWharton/Android-ViewPagerIndicator/
解决方案七:
actionbar+fragment
解决方案八:
viewpager+fragment,或者直接用viewpager
解决方案九:
手势 touch 以及viewpager 解决的办法很多呀!!
解决方案十:
手势 touch 以及viewpager 解决的办法很多呀!!
时间: 2024-11-02 11:36:49