Android編程實現(xiàn)在底端顯示選項卡的方法
本文實例講述了Android編程實現(xiàn)在底端顯示選項卡的方法。分享給大家供大家參考,具體如下:
1.layout 文件
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="@+id/edit_item_tab_host"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp" android:layout_weight="1">
<LinearLayout android:id="@+id/widget_layout_Blue"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="3px"
android:paddingRight="3px">
<LinearLayout android:id="@+id/titleLayout_person_check_road_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/layout_person_check_road_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/titleLayout_person_check_road_add"
android:layout_alignTop="@id/titleLayout_person_check_road_add"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout android:id="@+id/widget_layout_red"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="3px" android:paddingRight="3px">
<LinearLayout android:id="@+id/titleLayout_person_check_road_add1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/layout_person_check_road_add1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/titleLayout_person_check_road_add1"
android:layout_alignTop="@id/titleLayout_person_check_road_add1"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout android:id="@+id/widget_layout_green"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="3px" android:paddingRight="3px">
<LinearLayout android:id="@+id/titleLayout_person_check_road_add2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"> </LinearLayout>
<LinearLayout android:id="@+id/layout_person_check_road_add2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/titleLayout_person_check_road_add2"
android:layout_alignTop="@id/titleLayout_person_check_road_add2"
android:orientation="vertical"> </LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout android:id="@+id/widget_layout_yellow"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="3px" android:paddingRight="3px">
<LinearLayout android:id="@+id/titleLayout_person_check_road_add3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"> </LinearLayout>
<LinearLayout android:id="@+id/layout_person_check_road_add3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/titleLayout_person_check_road_add3"
android:layout_alignTop="@id/titleLayout_person_check_road_add3"
android:orientation="vertical"> </LinearLayout>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0" /> </LinearLayout>
</TabHost>
</LinearLayout>
2.Java 文件
import android.app.ActivityGroup;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TabHost;
import android.widget.TextView;
public class TabBottom extends ActivityGroup {
public static TabHost myTabhost;
private LayoutParams title_params = new LayoutParams(120, 50);
private LayoutParams content_params = new LayoutParams(158, 50);
private LinearLayout titleLayout, showViewLayout, titleLayout1,
showViewLayout1, titleLayout2, showViewLayout2, titleLayout3,
showViewLayout3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bottomtab);
myTabhost = (TabHost) findViewById(R.id.edit_item_tab_host);
myTabhost.setup(this.getLocalActivityManager());
titleLayout = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add);
showViewLayout = (LinearLayout) findViewById(R.id.layout_person_check_road_add);
titleLayout1 = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add1);
showViewLayout1 = (LinearLayout) findViewById(R.id.layout_person_check_road_add1);
titleLayout2 = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add2);
showViewLayout2 = (LinearLayout) findViewById(R.id.layout_person_check_road_add2);
titleLayout3 = (LinearLayout) findViewById(R.id.titleLayout_person_check_road_add3);
showViewLayout3 = (LinearLayout) findViewById(R.id.layout_person_check_road_add3);
myTabhost.addTab(myTabhost
.newTabSpec("One")
.setIndicator("收件箱",
getResources().getDrawable(R.drawable.icon))
.setContent(R.id.widget_layout_Blue));
myTabhost.addTab(myTabhost
.newTabSpec("Two")
.setIndicator("發(fā)件箱",
getResources().getDrawable(R.drawable.icon))
.setContent(R.id.widget_layout_green));
myTabhost.addTab(myTabhost
.newTabSpec("Three")
.setIndicator("垃圾箱",
getResources().getDrawable(R.drawable.icon))
.setContent(R.id.widget_layout_red));
myTabhost.addTab(myTabhost
.newTabSpec("Four")
.setIndicator("發(fā)送",
getResources().getDrawable(R.drawable.icon))
.setContent(R.id.widget_layout_yellow));
showInLayout();
showInLayout1();
showInLayout2();
showInLayout3();
}
/*
* 填充第一個選項卡頁面
*/
private void showInLayout() {
for (int i = 0; i < 10; i++) {
String condName = "名稱顯示1";
TextView tv = new TextView(this);
tv.setTextColor(Color.WHITE);
tv.setTextSize(16);
tv.setLayoutParams(title_params);
tv.setText(condName + ":");
titleLayout.addView(tv);
EditText tv1 = new EditText(this);
tv1.setTextSize(16);
tv1.setLayoutParams(content_params);
tv1.setText(condName);
showViewLayout.addView(tv1);
}
}
private void showInLayout1() {
for (int i = 0; i < 10; i++) {
String condName = "名稱顯示2";
TextView tv = new TextView(this);
tv.setTextColor(Color.WHITE);
tv.setTextSize(16);
tv.setLayoutParams(title_params);
tv.setText(condName + ":");
titleLayout1.addView(tv);
TextView tv1 = new TextView(this);
tv1.setTextColor(Color.WHITE);
tv1.setTextSize(16);
tv1.setLayoutParams(content_params);
tv1.setText(condName + ":");
showViewLayout1.addView(tv1);
}
}
private void showInLayout2() {
for (int i = 0; i < 10; i++) {
String condName = "名稱顯示3";
TextView tv = new TextView(this);
tv.setTextColor(Color.WHITE);
tv.setTextSize(16);
tv.setLayoutParams(title_params);
tv.setText(condName + ":");
titleLayout2.addView(tv);
TextView tv1 = new TextView(this);
tv1.setTextColor(Color.WHITE);
tv1.setTextSize(16);
tv1.setLayoutParams(content_params);
tv1.setText(condName + ":");
showViewLayout2.addView(tv1);
}
}
private void showInLayout3() {
for (int i = 0; i < 10; i++) {
String condName = "名稱顯示4";
TextView tv = new TextView(this);
tv.setTextColor(Color.WHITE);
tv.setTextSize(16);
tv.setLayoutParams(title_params);
tv.setText(condName + ":");
titleLayout3.addView(tv);
TextView tv1 = new TextView(this);
tv1.setTextColor(Color.WHITE);
tv1.setTextSize(16);
tv1.setLayoutParams(content_params);
tv1.setText(condName + ":");
showViewLayout3.addView(tv1);
}
}
}
效果如下:


更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進階教程》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android資源操作技巧匯總》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
- android TabHost(選項卡)的使用方法
- android 選項卡(TabHost)如何放置在屏幕的底部
- Android實現(xiàn)底部導航欄功能(選項卡)
- Android TabLayout(選項卡布局)簡單用法實例分析
- Android仿微信底部實現(xiàn)Tab選項卡切換效果
- Android多個TAB選項卡切換效果
- Android基于ViewPager Fragment實現(xiàn)選項卡
- Android利用Fragment實現(xiàn)Tab選項卡效果
- Android組件TabHost實現(xiàn)頁面中多個選項卡切換效果
- Android編程之TabWidget選項卡用法實例分析
- Android實現(xiàn)類似網(wǎng)易新聞選項卡動態(tài)滑動效果
- Android編程實現(xiàn)自定義Tab選項卡功能示例
相關(guān)文章
ANDROID BottomNavigationBar底部導航欄的實現(xiàn)示例
本篇文章主要介紹了ANDROID BottomNavigationBar底部導航欄的實現(xiàn)示例,非常具有實用價值,需要的朋友可以參考下2017-10-10
Android開發(fā)之MediaPlayer基本使用方法詳解
這篇文章主要介紹了Android開發(fā)之MediaPlayer基本使用方法,結(jié)合實例形式較為詳細的分析了MediaPlayer中的常用函數(shù)與基本使用技巧,需要的朋友可以參考下2017-05-05
Android開發(fā)中數(shù)據(jù)庫升級且表添加新列的方法
這篇文章主要介紹了Android開發(fā)中數(shù)據(jù)庫升級且表添加新列的方法,結(jié)合具體實例形式分析了Android數(shù)據(jù)庫升級開發(fā)過程中常見問題與相關(guān)操作技巧,需要的朋友可以參考下2017-09-09
Android編程實現(xiàn)監(jiān)控各個程序流量的方法
這篇文章主要介紹了Android編程實現(xiàn)監(jiān)控各個程序流量的方法,涉及Android針對應用包的遍歷,權(quán)限控制及相關(guān)屬性操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-12-12
從源代碼分析Android Universal ImageLoader的緩存處理機制
這篇文章主要介紹了從源代碼分析Android Universal ImageLoader的緩存處理機制 的相關(guān)資料,需要的朋友可以參考下2016-01-01
Android自定義ViewGroup的實現(xiàn)方法
這篇文章主要為大家詳細介紹了Android自定義ViewGroup的實現(xiàn)方法,感興趣的小伙伴們可以參考一下2016-05-05
Android實現(xiàn)直播聊天區(qū)域中頂部的漸變效果
最近在研究直播的彈幕,東西有點多,準備記錄一下免得自己忘了又要重新研究,下面這篇文章主要給大家介紹了關(guān)于Android如何實現(xiàn)直播聊天區(qū)域中頂部漸變效果的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2018-04-04

