[英]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.