Android 自定义TAB的三种实现方式

自定义TAB样式的实现
想必大家已看过很多资料的介绍
经在下总结,大致有以下三种实现方式:

1.自定义TabWidget
2.RadioGroup
3.ActivityGroup

下面本人就以上三种方式一一介绍,上图先:

\

\

\

不难看出,以上三种方式实现的效果基本一致(如无特殊需求的话)
要实现自定义TAB
无非是要实现以下三点:
1.TAB的主背景
2.TAB的item视图
3.TAB的ITEM选择效果




且看自定义TABWIDGET
-------------------------------------------->
在配置文件里TAB背景图如此设置便可:

                <TabWidget
	                        android:id="@android:id/tabs"
	                        android:layout_width="fill_parent"
	                        android:layout_height="wrap_content"
	                        android:padding="2dip"
	                        android:background="@drawable/tab_widget_background"
	                        android:layout_weight="0.0"/>
ITEM视图则在代码里设置
        for(int i = 0; i < count; i++)
	                {       
	                        TabSpec tabSpec = m_tabHost.newTabSpec(ConValue.mTextviewArray[i]).
	                                                                                                        setIndicator(getTabItemView(i)).
	                                                                                                        setContent(getTabItemIntent(i));
	                        m_tabHost.addTab(tabSpec);
	                        m_tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.selector_tab_background);
	                }

	private View getTabItemView(int index)
	        {

	                View view = mLayoutInflater.inflate(R.layout.tab_item_view, null);
	       
	                ImageView imageView = (ImageView) view.findViewById(R.id.imageview);

	                if (imageView != null)
	                {
	                        imageView.setImageResource(ConValue.mImageViewArray[index]);
	                }
	               
	                TextView textView = (TextView) view.findViewById(R.id.textview);
	               
	                textView.setText(ConValue.mTextviewArray[index]);
	       
	                return view;
	        }


 


转载:http://www.adobex.com/android/source/details/00000434.htm

你可能感兴趣的:(android,自定义TAB的三种实现方式)