Android控件之TabHost探究
来源:互联网 发布:.com域名申请 编辑:程序博客网 时间:2024/05/16 17:53
以下通过TabHost实现android选项卡。
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的创造者: 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创造者之一: 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类
- 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("选项卡一").setIndicator("选项卡一",
- getResources().getDrawable(R.drawable.png1)).setContent(R.id.tab01));
- tab.addTab(tab.newTabSpec("选项卡二").setIndicator("选项卡二",
- getResources().getDrawable(R.drawable.png2)).setContent(R.id.tab02));
- tab.addTab(tab.newTabSpec("选项卡三").setIndicator("选项卡三",
- getResources().getDrawable(R.drawable.png3)).setContent(R.id.tab03));
- }
- }
运行结果
- Android控件之TabHost探究
- Android控件之TabHost探究
- android控件之TabHost
- Android控件之TabHost
- Android控件之TabHost
- Android控件之TabHost
- android控件之tabhost tabwedget
- Android控件开发之TabHost
- Android控件之ImageView探究
- Android控件之ProgressBar探究
- Android控件之EditView探究
- Android控件之ToggleButton探究
- Android控件之ImageView探究
- Android控件之ScrollView探究
- Android控件之GridView探究
- Android控件之ProgressBar探究
- Android控件之TextView探究
- Android控件之Gallery探究
- Android控件之ProgressBar探究
- Android控件之TextView探究
- request对象和response对象
- POJ - 3982 - 高精度~滚动数组..
- Android控件之Gallery探究
- Android控件之TabHost探究
- Android控件之Spinner探究
- DB SQL养成一个好习惯是一笔财富
- DB 数据库差异备份与增量备份的不同之处
- C#鼠标穿透功能
- Python tools for penetration testers
- stl 学习笔记
- XP系统下查看工作组计算机非常慢的问题
- 俞永福:Web将逝世是伪命题 阅读器将永生,0HI