项目说明.txt 外部引用 原始文档 1 实现了tab的点击和滑动的操作,对于每次的都是启动一个activity。效果比较好看,需要的同学可以看下。 7.jpg 外部引用 原始文档 MainActivity.java 外部引用 原始文档 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 package com.and.netease; import com.and.netease.utils.MoveBg; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TabHost; public class MainActivity extends TabActivity { TabHost tabHost; TabHost.TabSpec tabSpec; RadioGroup radioGroup; RelativeLayout bottom_layout; ImageView img; int startLeft; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bottom_layout = (RelativeLayout) findViewById(R.id.layout_bottom); tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("news").setIndicator("News").setContent(new Intent(this, TabNewsActivity.class))); tabHost.addTab(tabHost.newTabSpec("topic").setIndicator("Topic").setContent(new Intent(this, TabTopicActivity.class))); tabHost.addTab(tabHost.newTabSpec("picture").setIndicator("Picture").setContent(new Intent(this, TabPicActivity.class))); tabHost.addTab(tabHost.newTabSpec("follow").setIndicator("Follow").setContent(new Intent(this, TabFollowActivity.class))); tabHost.addTab(tabHost.newTabSpec("vote").setIndicator("Vote").setContent(new Intent(this, TabVoteActivity.class))); radioGroup = (RadioGroup) findViewById(R.id.radiogroup); radioGroup.setOnCheckedChangeListener(checkedChangeListener); img = new ImageView(this); img.setImageResource(R.drawable.tab_front_bg); bottom_layout.addView(img); } private OnCheckedChangeListener checkedChangeListener = new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.radio_news: tabHost.setCurrentTabByTag("news"); // moveFrontBg(img, startLeft, 0, 0, 0); MoveBg.moveFrontBg(img, startLeft, 0, 0, 0); startLeft = 0; break; case R.id.radio_topic: tabHost.setCurrentTabByTag("topic"); MoveBg.moveFrontBg(img, startLeft, img.getWidth(), 0, 0); startLeft = img.getWidth(); break; case R.id.radio_pic: tabHost.setCurrentTabByTag("picture"); MoveBg.moveFrontBg(img, startLeft, img.getWidth() * 2, 0, 0); startLeft = img.getWidth() * 2; break; case R.id.radio_follow: tabHost.setCurrentTabByTag("follow"); MoveBg.moveFrontBg(img, startLeft, img.getWidth() * 3, 0, 0); startLeft = img.getWidth() * 3; break; case R.id.radio_vote: tabHost.setCurrentTabByTag("vote"); MoveBg.moveFrontBg(img, startLeft, img.getWidth() * 4, 0, 0); startLeft = img.getWidth() * 4; break; default: break; } } }; } netease_news.zip