新浪微博布局学习——妙用TabHost

转载至:新浪微博布局学习——妙用TabHost

注:TabWidget 布局里边放入各个Tab挺有意思的。这样做到即见即所得的效果。


        
            
            
            
            
            
        

如果遇到特殊的TabWidget布局可以采取这种方式,一般的TabWidget可以不需要结合 RadioButton,用它自己自带的就好了。如下:

	mHost.addTab(buildTabSpec(TAB_COMMENT,"商家点评",R.drawable.tab1_selector));
			mHost.addTab(buildTabSpec(TAB_DESC,"商家介绍",R.drawable.tab2_selector));
			mHost.addTab(buildTabSpec(TAB_INFO,"商家信息",R.drawable.tab3_selector));
 private TabHost.TabSpec buildTabSpec(String tag, String tagName,
   int drawableId) {
  View tagView = getTabView(drawableId, tagName);
  return this.mHost.newTabSpec(tag).setIndicator(tagView)
    .setContent(this);
 }
 
 
 private View getTabView(int drawableId, final String tabName) {
  final View view = View.inflate(this, R.layout.tab_layout, null);//自定义布局
  final View bgLayout =  view.findViewById(R.id.bglayout);
  final TextView tabView = (TextView) view.findViewById(R.id.tab);
  tabView.setText(tabName);
  bgLayout.setBackgroundResource(drawableId);
  return view;
 }

tab_layout.xml

   


	private TabHost.TabSpec buildTabSpec(String tag, String tagName,
			int drawableId) {
		View tagView = getTabView(drawableId, tagName);
		return this.mHost.newTabSpec(tag).setIndicator(tagView)
				.setContent(this);
	}
	
	
	private View getTabView(int drawableId, final String tabName) {
		final View view = View.inflate(this, R.layout.tab_layout, null);
		final View bgLayout =  view.findViewById(R.id.bglayout);
		final TextView tabView = (TextView) view.findViewById(R.id.tab);
		tabView.setText(tabName);
		bgLayout.setBackgroundResource(drawableId);
		return view;
	}


 

 

你可能感兴趣的:(android,开发日志,新浪微博,android,radiobutton,layout,button,string)