<!-- 上面显示 图片 下面显示说明的文字-->
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:id="@+id/tab_imageview_icon" android:layout_width="fill_parent" android:layout_height="32.0dip" android:scaleType="fitCenter" />
<TextView android:id="@+id/tab_textview_title" android:textSize="11.0sp" android:ellipsize="marquee" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:marqueeRepeatLimit="1" />
</LinearLayout>
<!-- Tab的布局文件 -->
<!-- 定义 TabHost->
<?xml version="1.0" encoding="utf-8"?>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/tab_bkg"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</TabHost>
显示文件
package my.weibo;
import my.weibo.R;
import my.weibo.R.drawable;
import my.weibo.R.id;
import my.weibo.R.layout;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
public class TelentWeiBoActivity extends TabActivity {
private TabHost tabHost;
private static final String HOME = "主页";
private static final String REFER = "提及";
private static final String SECRET = "私信";
private static final String SEARCH = "搜索";
private static final String ATTENTIION = "关注";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabhos);
tabHost=this.getTabHost();
View view=View.inflate(TelentWeiBoActivity.this, R.layout.tab, null);
((ImageView)view.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.home);
((TextView)view.findViewById(R.id.tab_textview_title)).setText(HOME);
TabHost.TabSpec tabSpec=tabHost.newTabSpec(HOME).setIndicator(view).setContent(new Intent(this, 需要显示的Activity.class));
tabHost.addTab(tabSpec);
View view1=View.inflate(TelentWeiBoActivity.this, R.layout.tab, null);
((ImageView)view1.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.refer);
((TextView)view1.findViewById(R.id.tab_textview_title)).setText(REFER);
TabHost.TabSpec tabSpec1=tabHost.newTabSpec(REFER).setIndicator(view1).setContent(new Intent(this, 需要显示的Activity.class));
tabHost.addTab(tabSpec1);
View view2=View.inflate(TelentWeiBoActivity.this, R.layout.tab, null);
((ImageView)view2.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.secret);
((TextView)view2.findViewById(R.id.tab_textview_title)).setText(SECRET);
TabHost.TabSpec tabSpec2=tabHost.newTabSpec(SECRET).setIndicator(view2).setContent(new Intent(this, 需要显示的Activity.class));
tabHost.addTab(tabSpec2);
View view3=View.inflate(TelentWeiBoActivity.this, R.layout.tab, null);
((ImageView)view3.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.search);
((TextView)view3.findViewById(R.id.tab_textview_title)).setText(SEARCH);
TabHost.TabSpec tabSpec3=tabHost.newTabSpec(SEARCH).setIndicator(view3).setContent(new Intent(this, 需要显示的Activity.class));
tabHost.addTab(tabSpec3);
View view4=View.inflate(TelentWeiBoActivity.this, R.layout.tab, null);
((ImageView)view4.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.attention);
((TextView)view4.findViewById(R.id.tab_textview_title)).setText(ATTENTIION);
TabHost.TabSpec tabSpec4=tabHost.newTabSpec(ATTENTIION).setIndicator(view4).setContent(new Intent(this, 需要显示的Activity.class));
tabHost.addTab(tabSpec4);
}
}
我所做的效果如下