[英]TabHost Animation with changed tab
我尝试在选项卡更改时向其中添加动画,我有一个列表视图作为选项卡,现在我可以使用动画了。 使用这个
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();
}
});
和这个
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;
}
基于以下帖子:
但是在列表视图中,我上面有一个标题,并且我希望标题保留下来并仅更改列表,我该如何更改呢?
您可以简单地调用getTabHost().getCurrentView()
链的findViewById()
方法来查找ListView
并为其设置动画。
getTabHost().setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
View currentView = getTabHost().getCurrentView();
ListView listView = (ListView) currentView.findViewById(R.id.your_list_id);
if (getTabHost().getCurrentTab() > currentTab)
{
listView.setAnimation( inFromRightAnimation() );
}
else
{
listView.setAnimation( outToRightAnimation() );
}
currentTab = getTabHost().getCurrentTab();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.