Android编程实现在底端显示选项卡的方法
短信预约 -IT技能 免费直播动态提醒
本文实例讲述了Android编程实现在底端显示选项卡的方法。分享给大家供大家参考,具体如下:
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("发件箱",
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);
}
}
}
效果如下:
更多关于Android相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android编程之activity操作技巧总结》、《Android资源操作技巧汇总》、《Android操作json格式数据技巧总结》、《Android数据库操作技巧总结》、《Android编程开发之SD卡操作方法汇总》、《Android视图View技巧总结》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。
您可能感兴趣的文章:android TabHost(选项卡)的使用方法android 选项卡(TabHost)如何放置在屏幕的底部Android实现底部导航栏功能(选项卡)Android TabLayout(选项卡布局)简单用法实例分析Android仿微信底部实现Tab选项卡切换效果Android多个TAB选项卡切换效果Android基于ViewPager Fragment实现选项卡Android利用Fragment实现Tab选项卡效果Android组件TabHost实现页面中多个选项卡切换效果Android编程之TabWidget选项卡用法实例分析Android实现类似网易新闻选项卡动态滑动效果Android编程实现自定义Tab选项卡功能示例
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341