更多参考:http://www.360doc.com/content/12/0515/13/7857928_211171985.shtml

效果图:




TabHost的布局:

<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@android:id/tabhost"    android:layout_width="fill_parent"    android:layout_height="fill_parent" >    <LinearLayout        android:id="@+id/linearLayout1"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical" >        <TabWidget            android:id="@android:id/tabs"            android:layout_width="fill_parent"            android:layout_height="wrap_content" >        </TabWidget>        <FrameLayout            android:id="@android:id/tabcontent"            android:layout_width="fill_parent"            android:layout_height="fill_parent" >        </FrameLayout>    </LinearLayout></TabHost>


TabHost的主文件:

public class MainActivity extends TabActivity {    String[] title = new String[]{"ni","wo","ta","we"};      View userTab,articeTab,feedTab,weTab;      View[] tabs = new View[]{userTab,articeTab,feedTab,weTab};      @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                TabHost tabHost = getTabHost();          tabHost.setup();   //Call setup() before adding tabs if loading TabHost using findViewById().                     for(int i=0;i<tabs.length;i++){             Intent intent = new Intent(this,AActivity.class);            tabs[i] = (View) LayoutInflater.from(this).inflate(R.layout.tabmini, null);              ImageView text = (ImageView) tabs[i].findViewById(R.id.tab_label);                         tabHost.addTab(tabHost.newTabSpec(title[i]).setIndicator(tabs[i]).setContent(intent));             tabHost.setCurrentTab(1);        }      }}

TabHost里面的布局(tabmini.xml):

<?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"        android:layout_width="fill_parent"      android:layout_height="40dp"      android:paddingLeft="5dip"      android:paddingRight="5dip"      android:background="#ff0000">              <ImageView android:id="@+id/tab_label"            android:layout_width="fill_parent"          android:layout_height="wrap_content"          android:layout_centerInParent="true"          android:gravity="center"          android:background="@drawable/btndown"        />   </RelativeLayout>

更多相关文章

  1. Android(安卓)Themes关于totalBar总结
  2. Android(安卓)UI控件详解-CheckBox(多选框)
  3. fragment
  4. Android(安卓)4.0 gallery2 生成video thumbnail的过程
  5. android上,实现直接在屏幕上显示点击位置,方便调试。
  6. Android(安卓)--- 图片的特效处理
  7. Android(安卓)--- 图片的特效处理
  8. 初涉Android之ContentProvider
  9. android中生成和使用jar 分享

随机推荐

  1. Android系统升级全流程
  2. Android输入子系统之启动过程分析
  3. Android消息推送简介
  4. Android学习路线总结,绝对干货
  5. Android实现程序前后台切换效果
  6. android主流UI布局
  7. android looper介绍
  8. Android(安卓)adb不是内部或外部命令 问
  9. Dex2jar 与 JD-GUI快速反编译Android(安
  10. Android通过软解码播放视频