安卓布局——tabhost底部
来源:互联网 发布:三毛淘宝小号 编辑:程序博客网 时间:2024/06/06 20:53
效果:点击则会跳转到相应的界面,并且图片样式也会改变
源码:
layout文件
<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0.0dip" android:layout_weight="1.0" /> <TabWidget android:id="@android:id/tabs" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0" /> <LinearLayout android:gravity="bottom" android:layout_gravity="bottom" android:orientation="horizontal" android:id="@+id/main_tab_grodup" android:background="@drawable/tabbar" android:paddingTop="2.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content"> <FrameLayout android:background="@null" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0"> <LinearLayout android:id="@+id/main_layout_settings" android:gravity="bottom|center" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout android:id="@+id/main_tab_settings" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" > <ImageView android:id="@+id/img_tab_settings" android:layout_width="fill_parent" android:layout_height="50dp" android:src="@drawable/xk" android:layout_centerHorizontal="true"/> <TextView android:layout_below ="@id/img_tab_settings" android:id="@+id/img_settings_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:textColor="@color/grey" android:text="参数设置"/> </RelativeLayout> </LinearLayout> </FrameLayout> <FrameLayout android:background="@null" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0"> <LinearLayout android:id="@+id/main_layout_addExam" android:gravity="bottom|center" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout android:id="@+id/main_tab_addExam" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" > <ImageView android:id="@+id/img_tab_addExam" android:layout_width="fill_parent" android:layout_height="50dp" android:src="@drawable/sk1" android:layout_centerHorizontal="true"/> <TextView android:layout_below ="@id/img_tab_addExam" android:id="@+id/tab_addExam_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:textColor="@color/grey" android:textSize="15sp" android:text="数据展示"/> </RelativeLayout> </LinearLayout> </FrameLayout> </LinearLayout> </LinearLayout></TabHost>
MAinActivity源码
package com.zw.layout1;import android.support.v7.app.ActionBarActivity;import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.RelativeLayout;import android.widget.TabHost;import android.widget.TextView;public class MainActivity extends TabActivity {TabHost tabHost; private TextView main_tab_unread_tv; private RelativeLayout main_tab_addExam,main_tab_settings; private LinearLayout main_layout_addExam,main_layout_settings; private ImageView img_tab_addExam,img_tab_settings ; private TextView text_tab_addExam,text_tab_settings; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //this.requestWindowFeature(Window.FEATURE_NO_TITLE);去掉标题栏 setContentView(R.layout.activity_main); initTab(); init(); } private void init() { //点击底部 main_tab_addExam = (RelativeLayout) findViewById(R.id.main_tab_addExam); main_tab_settings=(RelativeLayout) findViewById(R.id.main_tab_settings); //底部图片跟换 img_tab_addExam = (ImageView) findViewById(R.id.img_tab_addExam) ; img_tab_settings = (ImageView) findViewById(R.id.img_tab_settings) ; //底部文字 text_tab_addExam = (TextView) findViewById(R.id.tab_addExam_text) ; text_tab_settings = (TextView) findViewById(R.id.img_settings_text) ; main_layout_addExam=(LinearLayout) findViewById(R.id.main_layout_addExam); main_layout_settings=(LinearLayout) findViewById(R.id.main_layout_settings); //图片点亮 img_tab_addExam.setImageResource(R.drawable.sk1); img_tab_settings.setImageResource(R.drawable.xk); //背景点亮// main_layout_addExam.setBackgroundResource(0);// main_layout_settings.setBackgroundResource(R.drawable.labelbg); main_tab_addExam.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { tabHost.setCurrentTabByTag("first"); //图片点亮 img_tab_addExam.setImageResource(R.drawable.sk1); img_tab_settings.setImageResource(R.drawable.xk); //背景点亮// main_layout_addExam.setBackgroundResource(R.drawable.labelbg);// main_layout_settings.setBackgroundResource(0); } }); main_tab_settings.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub tabHost.setCurrentTabByTag("second"); //图片点亮 img_tab_addExam.setImageResource(R.drawable.sk); img_tab_settings.setImageResource(R.drawable.xk1); //背景点亮// main_layout_addExam.setBackgroundResource(0);;// main_layout_settings.setBackgroundResource(R.drawable.labelbg); //文字点亮 //text_tab_addExam.setTextColor(color.grey); //text_tab_settings.setTextColor(color.darkseagreen); } }); } private void initTab(){ tabHost=getTabHost(); tabHost.addTab(tabHost.newTabSpec("first").setIndicator("first").setContent( new Intent(this,Doxingxi.class))); tabHost.addTab(tabHost.newTabSpec("second").setIndicator("second").setContent( new Intent(this, Showxingxi.class))); }}
源码下载:
http://download.csdn.net/download/zw1996/10002850
阅读全文
0 0
- 安卓布局——tabhost底部
- 安卓精美底部导航栏的实现TabHost
- 安卓开发设置Tabhost位于底部的方法
- 安卓UI--底部导航栏--TabHost、TabActivity
- Android 布局——TabHost
- 安卓在fragment里面使用TabHost布局
- 安卓布局——ViewPager布局
- 安卓键盘弹出是底部布局整体上移实现
- 底部TabHost
- 底部TabHost
- 布局学习——妙用TabHost
- 浪微博布局学习——妙用TabHost
- 安卓学习笔记(八)tabhost——安卓第六天
- Android仿新浪微博底部布局TabHost
- 安卓控件使用系列29:TabHost卡片的使用方法2不继承TabActivity、TabHost控件、一个布局文件
- 安卓控件使用系列30:TabHost卡片的使用方法3不继承TabActivity、TabHost控件、多个布局文件
- 底部tabhost研究一(TabHost 不是最外面的布局)
- 安卓 TabHost控件用法
- javaweb中的文件上传之fileupload组件
- x64+VS2013+opencv3.3.0自行编译源码安装及配置过程
- JAVA-多态
- 如何假装成为优秀的码农
- 一顿饭让你学会作业调度和进程调度
- 安卓布局——tabhost底部
- 初探Java源码之LinkedList
- Java多线程编程-(3)-从一个错误的双重校验锁代码谈一下volatile关键字
- 简要分析ZooKeeper基本原理
- Java多线程编程-(4)-线程本地ThreadLocal的介绍与使用
- Java多线程编程-(1)-线程安全和锁Synchronized概念
- 为什么工资高的程序员很少炫富?
- 图解Storm并发机制及其执行流程
- POJ 3057 Evacuation