您的位置:首页 > 其它

仿鲁大师界面(实现启动动画和TabHost选项卡切换时滑动动画)

2014-10-23 19:12 369 查看
SplashActivity画面:



TabHost的OnTabChangedListener切换时动画:



SplashActivity代码如下:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.ludashi.beachmark.R;

public class SplashActivity extends Activity{

private Handler handler = new Handler(){

@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
Intent intent = new Intent(SplashActivity.this,MainTabActivity.class);
startActivity(intent);
SplashActivity.this.finish();
break;
}
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);

handler.sendEmptyMessageDelayed(0, 3000);
}

}
</pre>TabHost部分代码:<p></p><p></p><pre name="code" class="java">protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_tab);

mTabHost = this.getTabHost();
mTabSpec1 = mTabHost.newTabSpec("tab_1")
.setIndicator("手机检测", getResources().getDrawable(R.drawable.tabhost_evaluation))
.setContent(new Intent(this,EvaluationActivity.class));
mTabSpec2 = mTabHost.newTabSpec("tab_2")
.setIndicator("验机", getResources().getDrawable(R.drawable.tabhost_verify))
.setContent(new Intent(this,VerifyActivity.class));
mTabSpec3 =mTabHost.newTabSpec("tab_3")
.setIndicator("设备", getResources().getDrawable(R.drawable.tabhost_device))
.setContent(new Intent(this,DeviceActivity.class));
mTabSpec4 = mTabHost.newTabSpec("tab_4")
.setIndicator("更多", getResources().getDrawable(R.drawable.tabhost_more))
.setContent(new Intent(this,MoreActivity.class));

mTabHost.addTab(mTabSpec1);
mTabHost.addTab(mTabSpec2);
mTabHost.addTab(mTabSpec3);
mTabHost.addTab(mTabSpec4);

mTabHost.setCurrentTab(0);

updateTab(mTabHost);
mTabHost.setOnTabChangedListener(new MyTabChangedLiListener());
}

private final class MyTabChangedLiListener implements OnTabChangeListener{

@Override
public void onTabChanged(String tabId) {
mCurTabIndex = mTabHost.getCurrentTab();
System.out.println(mCurTabIndex);
//System.out.println(mTabHost.getTabContentView().getChildCount());
if(mCurTabIndex>mLastTabIndex){
mTabHost.getTabContentView().getChildAt(mLastTabIndex).startAnimation(AnimationUtils.loadAnimation(getApplication(), R.anim.left_exit_anim));
mTabHost.getCurrentView().startAnimation(AnimationUtils.loadAnimation(getApplication(), R.anim.right_enter_anim));
}
if(mCurTabIndex<mLastTabIndex){
mTabHost.getTabContentView().getChildAt(mLastTabIndex).startAnimation(AnimationUtils.loadAnimation(getApplication(), R.anim.right_exit_anim));
mTabHost.getCurrentView().startAnimation(AnimationUtils.loadAnimation(getApplication(), R.anim.left_enter_anim));
}
mLastTabIndex = mCurTabIndex;
}

}


工程文件地址:

链接: http://pan.baidu.com/s/1c06H59u
密码: rr2j
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: