Android TabHost中實現標籤的滾動

http://www.cnblogs.com/shirley-1019/archive/2013/04/10/3012824.htmlhtml

很是漂亮的一段代碼:android

public class TabhostTestActivity extends TabActivity implements
       TabContentFactory {
   private String[] lables = new String[] { "首頁", "消息", "朋友", "更多" };
 private int[] icons = new int[] { R.drawable.ic_home, R.drawable.ic_msg, R.drawable.ic_friend, R.drawable.ic_more };
ide

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.tabhost);
       TabHost th = getTabHost();
       tabHost = getTabHost();
  for (int i = 0; i < lables.length; i++) {
   View view = LayoutInflater.from(this).inflate(R.layout.menu, null);
   ImageView menu_ic = (ImageView) view.findViewById(R.id.menu_ic);
   menu_ic.setImageResource(icons[i]);
   TextView text = (TextView) view.findViewById(R.id.menu_lable);
   text.setText(lables[i]);
   tabHost.addTab(tabHost.newTabSpec(String.valueOf(i)).setIndicator(view).setContent(this));
  }
  tabHost.setCurrentTab(0);   }this

 @Override
 public void onTabChanged(String tabId) {
  // tabId 爲newTabSpec(String tag) 中傳入的字符串tag,這裏tag是0,1,2,3 能夠轉換爲整形便於判斷
  int tabID = Integer.valueOf(tabId);
  for (int i = 0; i < mTabWidget.getChildCount(); i++) {
   if (i == tabID) {
    mTabWidget.getChildAt(i).setBackgroundResource(
      R.drawable.indicator_selected);
   } else {
    mTabWidget.getChildAt(i).setBackgroundResource(
      R.drawable.indicator_unselected);
   }
  }
 }spa

 

TabHost經過手勢切換Activity.net

http://www.eoeandroid.com/thread-238527-1-1.html  簡直帥爆了htm


2.ViewPager+RadioButton仿QQ效果blog

http://my.oschina.net/qibin/blog/316650字符串

原理說的很明白。get

相關文章
相關標籤/搜索