Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 525|回复: 0

Android 自定义选项卡-  Android学习

[复制链接]

该用户从未签到

发表于 2011-10-24 14:38:03 | 显示全部楼层 |阅读模式
    我们今天就来说说屏幕底端的选项卡,这个是很有必要的。那么我就不多说了,还是上代码吧,最后我们还有效果图:

java代码: <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

androidrientation="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>
复制代码
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);

}

}



}
复制代码
效果图:





回复

使用道具 举报

该用户从未签到

发表于 2011-10-24 14:38:10 | 显示全部楼层

Re:Android

支持下 好东西
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

GMT+8, 2025-1-11 11:42 , Processed in 0.361042 second(s), 45 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表