`

android > tabHost > 微博布局风格

 
阅读更多

tab.xml 布局

 

<?xml version="1.0" encoding="utf-8"?>
    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        xmlns:android="http://schemas.android.com/apk/res/android">
        
        <RelativeLayout 
            android:id="@+id/relativeLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
                
                    <TabWidget
                        android:id="@android:id/tabs"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"/>
           
        </RelativeLayout>
    </TabHost>

----- 其中 解决 TAB层 遮住 了后面 的 主层的解决办法 的 布局

<?xml version="1.0" encoding="utf-8"?>
    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        xmlns:android="http://schemas.android.com/apk/res/android">
        
        <LinearLayout 
            android:id="@+id/relativeLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_weight="1" 
                android:layout_height="fill_parent" />
                
            <TabWidget
                  android:id="@android:id/tabs"
                  android:layout_width="fill_parent"
                  android:layout_weight="10" 
                  android:layout_height="fill_parent"/>
           
        </LinearLayout>
    </TabHost>
 

 

 

 

 

tab_list.xml

 

<?xml version="1.0" encoding="UTF-8"?>
 
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:paddingTop="3dip" android:paddingBottom="3dip" android:background="#393C42"
 
  xmlns:android="http://schemas.android.com/apk/res/android">
 
    <ImageView android:id="@+id/tab_imageview_icon" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scaleType="fitCenter" />
 
    <TextView android:id="@+id/tab_textview_title" android:textColor="#FFFFFF" android:textSize="10dip"  android:ellipsize="marquee" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:marqueeRepeatLimit="1" />
 
</LinearLayout>

 

 

主activity

 

package tab.mft;

import cfg.mft.CfgIndex;
import login.mft.LoginAddSensor;
import login.mft.LoginIndexActivity;
import remote2.mft.R;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

public class TabIndex extends TabActivity{
	
	private TabHost tabHost;  
    private static final String SYS = "系统";  
    private static final String SERVERS = "服务";  
    private static final String MORE = "更多";    
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);	
		setContentView(R.layout.tab);
		tabHost=getTabHost();
		
		final View view=View.inflate(TabIndex.this, R.layout.tab_list, null);
		view.setBackgroundColor(Color.rgb(33,36,41)); //默认第一个点亮
		((ImageView)view.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_home_sel); //默认第一个点亮
		((TextView)view.findViewById(R.id.tab_textview_title)).setText(SYS); 
		TabHost.TabSpec tabSpec=tabHost.newTabSpec(SYS).setIndicator(view).setContent(new Intent(TabIndex.this, LoginIndexActivity.class));
		tabHost.addTab(tabSpec);
		
		final View view1=View.inflate(TabIndex.this, R.layout.tab_list, null);
		((ImageView)view1.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_selfinfo_nor);
		((TextView)view1.findViewById(R.id.tab_textview_title)).setText(SERVERS); 
		TabHost.TabSpec tabSpec1=tabHost.newTabSpec(SERVERS).setIndicator(view1).setContent(new Intent(TabIndex.this, LoginAddSensor.class));
		tabHost.addTab(tabSpec1);
		
		final View view2=View.inflate(TabIndex.this, R.layout.tab_list, null);
		((ImageView)view2.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_more_nor);
		((TextView)view2.findViewById(R.id.tab_textview_title)).setText(MORE); 
		TabHost.TabSpec tabSpec2=tabHost.newTabSpec(MORE).setIndicator(view2).setContent(new Intent(TabIndex.this, LoginAddSensor.class));
		tabHost.addTab(tabSpec2);
		
		tabHost.setCurrentTab(0);
		
		//设置切换监听
		tabHost.setOnTabChangedListener(new OnTabChangeListener(){
			public void onTabChanged(String tabId){
				((ImageView)view.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_home_nor);
				view.setBackgroundColor(Color.rgb(57,60,66));
				((ImageView)view1.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_selfinfo_nor);
				view1.setBackgroundColor(Color.rgb(57,60,66));
				((ImageView)view2.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_more_nor);
				view2.setBackgroundColor(Color.rgb(57,60,66));
				
				if(tabId.equals(SYS)){
					((ImageView)view.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_home_sel);
					view.setBackgroundColor(Color.rgb(33,36,41));
				}
				if(tabId.equals(SERVERS)){
					((ImageView)view1.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_selfinfo_sel);
					view1.setBackgroundColor(Color.rgb(33,36,41));
				}
				if(tabId.equals(MORE)){
					((ImageView)view2.findViewById(R.id.tab_imageview_icon)).setImageResource(R.drawable.icon_more_sel);
					view2.setBackgroundColor(Color.rgb(33,36,41));
				}
			}
		});

	}
}
分享到:
评论

相关推荐

    android自定义tabhost

    在Android开发中,TabHost是一个非常重要的组件,它允许开发者创建多标签的界面,类似于浏览器中的标签页。本文将深入探讨如何自定义TabHost来实现类似新浪微博的效果,从而提升用户体验和应用的交互性。 首先,...

    仿新浪微博TabHost菜单

    总结,"仿新浪微博TabHost菜单"的实现涉及Android的布局管理、Intent机制、自定义视图以及事件监听等多个方面。开发者需要熟练掌握这些基础知识,才能创建出富有个性和用户体验良好的App界面。通过这个特效集锦系列...

    android底部tab布局

    我们将探讨如何利用Android的TabHost组件以及相关的布局技术来创建类似的用户界面。 首先,让我们了解TabHost组件。TabHost是Android提供的一个容器,它允许你在同一个视图中显示多个Tab(标签页)。每个Tab都可以...

    美化TabHost

    在Android应用开发中,TabHost是一个非常常见的组件,它用于创建多标签的界面,让用户能够通过不同的标签页浏览和切换不同的功能。美化TabHost是为了提供更好的用户体验,使其更符合当前主流设计趋势,如新浪微博...

    Android程序开发之自定义设置TabHost,TabWidget样式

    在Android程序开发中,自定义TabHost和TabWidget的样式是一项常见的任务,用于创建类似京东商城和新浪微博底部菜单栏的效果。TabHost和TabWidget是Android SDK提供的组件,用于实现多标签界面,让用户能够轻松地在...

    高仿新浪微博底栏效果(FragmentTabHost实现)

    `FragmentTabHost`是Android SDK提供的一种用于在Tab布局中管理`Fragment`的类,它继承自`TabHost`,并且对`TabHost`进行了扩展,使得我们可以在每个标签页中放入`Fragment`,而不是传统的`View`。这种方式更有利于...

    Android-app.rar

    Android RecycleView+任意头尾布局+拖拽换位+拖拽删除demo Android sql练习合集 Android 仿12306 Android 优秀计步器 Android 体重计算源码 Android 使用Gallery_tabhost实现标签效果图源码 Android 例子源码根据CPU...

    TabHost和ViewPager

    开发者需要将各个小部件添加到TabHost中,并为每个标签设置相应的活动或布局。TabHost通过`setup()`方法初始化,然后使用`addTab()`方法为每个标签添加对应的显示内容。在设置完所有标签后,通过`setTabWidget()`和`...

    android 选项卡 示例

    要创建一个`TabHost`,首先需要在XML布局文件中声明一个`TabHost`元素,并设置其id为`android:id/tabhost`。接着,在代码中通过`TabHost`的`setup()`方法初始化它,并添加所需的选项卡。 2. **定义TabWidget** `...

    TabHostDemo

    综上所述,`TabHostDemo`是一个演示如何使用`FragmentTabHost`构建多标签界面的实例,它结合了`Fragment`的灵活性和`TabHost`的便利性,是Android应用中实现类似微博主界面功能的常见解决方案。通过深入学习和实践这...

Global site tag (gtag.js) - Google Analytics