Android控件之TabHost用法實(shí)例分析
本文實(shí)例講述了Android控件之TabHost用法。分享給大家供大家參考。具體如下:
以下通過(guò)TabHost實(shí)現(xiàn)android選項(xiàng)卡。
main.xml布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/tab01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView android:id="@+id/iv01"
android:scaleType="fitXY"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/andy"/>
<TextView android:id="@+id/tv01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24dip"
android:text="Android的創(chuàng)造者: Andy Rubin"/>
</LinearLayout>
<LinearLayout android:id="@+id/tab02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView android:id="@+id/iv02"
android:scaleType="fitXY"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bill"/>
<TextView android:id="@+id/tv02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24dip"
android:text="Java創(chuàng)造者之一: Bill Joy"/>
</LinearLayout>
<LinearLayout android:id="@+id/tab03"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView android:id="@+id/iv03"
android:scaleType="fitXY"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/torvalds"/>
<TextView android:id="@+id/tv03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24dip"
android:text="Linux之父: Linus Torvalds"/>
</LinearLayout>
</LinearLayout>
TabHostActivity類(lèi):
package com.ljq.activity;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;
public class TabHostActivity extends TabActivity{
private TabHost tab=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tab=this.getTabHost();
LayoutInflater.from(this).inflate(R.layout.main, tab.getTabContentView(), true);
tab.addTab(tab.newTabSpec("選項(xiàng)卡一").setIndicator("選項(xiàng)卡一",
getResources().getDrawable(R.drawable.png1)).setContent(R.id.tab01));
tab.addTab(tab.newTabSpec("選項(xiàng)卡二").setIndicator("選項(xiàng)卡二",
getResources().getDrawable(R.drawable.png2)).setContent(R.id.tab02));
tab.addTab(tab.newTabSpec("選項(xiàng)卡三").setIndicator("選項(xiàng)卡三",
getResources().getDrawable(R.drawable.png3)).setContent(R.id.tab03));
}
}
運(yùn)行結(jié)果:

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
- Android TabHost選項(xiàng)卡標(biāo)簽圖標(biāo)始終不出現(xiàn)的解決方法
- Android組件TabHost實(shí)現(xiàn)頁(yè)面中多個(gè)選項(xiàng)卡切換效果
- android TabHost(選項(xiàng)卡)的使用方法
- android 選項(xiàng)卡(TabHost)如何放置在屏幕的底部
- android中TabHost的圖標(biāo)(48×48)和文字疊加解決方法
- Android TabLayout(選項(xiàng)卡布局)簡(jiǎn)單用法實(shí)例分析
- Android實(shí)現(xiàn)底部導(dǎo)航欄功能(選項(xiàng)卡)
- Android多個(gè)TAB選項(xiàng)卡切換效果
- Android仿微信底部實(shí)現(xiàn)Tab選項(xiàng)卡切換效果
- Android開(kāi)發(fā)之TabHost選項(xiàng)卡及相關(guān)疑難解決方法
相關(guān)文章
Android Canvas drawText文字居中的一些事(圖解)
這篇文章主要給大家介紹了關(guān)于Android Canvas drawText文字居中的一些事,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12
Android自定義控件之組合控件學(xué)習(xí)筆記分享
這篇文章主要為大家分享了Android自定義控件之組合控件學(xué)習(xí)筆記,具有一定的實(shí)用性和參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05
Android利用CountDownTimer實(shí)現(xiàn)倒計(jì)時(shí)功能 Android實(shí)現(xiàn)停留5s跳轉(zhuǎn)到登錄頁(yè)面
這篇文章主要為大家詳細(xì)介紹了Android利用CountDownTimer實(shí)現(xiàn)倒計(jì)時(shí)功能,Android實(shí)現(xiàn)停留5s跳轉(zhuǎn)到登錄頁(yè)面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
kotlin使用Dagger2的過(guò)程全紀(jì)錄
Dagger2是一款基于Java注解,在編譯階段完成依賴(lài)注入的開(kāi)源庫(kù),主要用于模塊間解耦,方便進(jìn)行測(cè)試。下面這篇文章主要給大家介紹了關(guān)于kotlin使用Dagger2的過(guò)程的相關(guān)資料,需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-03-03
Android ListView在Fragment中的使用示例詳解
這篇文章主要介紹了Android ListView在Fragment中的使用,因?yàn)楣ぷ饕恢痹谟胢vvm框架,因此這篇文章是基于mvvm框架寫(xiě)的,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09
Android?動(dòng)態(tài)加載?so實(shí)現(xiàn)示例詳解
這篇文章主要為大家介紹了Android?動(dòng)態(tài)加載?so實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
Android中實(shí)現(xiàn)下載和解壓zip文件功能代碼分享
這篇文章主要介紹了Android中實(shí)現(xiàn)下載和解壓zip文件功能代碼分享,本文直接給出了實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-03-03

