Android中在底端显示选项卡
2011-05-20 18:20 蓝之风 阅读(681) 评论(0) 编辑 收藏 举报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>
<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("发件箱",
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("发送",
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);
}
}
}
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("发件箱",
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("发送",
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);
}
}
}
效果如下:
作者:蓝之风
出处:http://www.cnblogs.com/vaiyanzi/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架