tabhostandbadgeview

阅读更多

效果

-------------------------------------------------------------------------------------------------------------------------------

 tabhostandbadgeview_第1张图片tabhostandbadgeview_第2张图片

 

素材

-------------------------------------------------------------------------------------------------------------------------------

 tabhostandbadgeview_第3张图片

tab_select.xml

-------------------------------------------------------------------------------------------------------------------------------

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

    

    

    

 

activity_main.xml

-------------------------------------------------------------------------------------------------------------------------------

    android:id="@+id/mtabs"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical" >

 

    

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:orientation="vertical" >

 

        

            android:id="@android:id/tabs"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_weight="0" >

        

 

        

            android:id="@android:id/tabcontent"

            android:layout_width="fill_parent"

            android:layout_height="fill_parent"

            android:layout_weight="1" >

 

            

                android:id="@+id/tab1"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Tab 1"

                android:textSize="20dip" />

 

            

                android:id="@+id/tab2"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Tab 2"

                android:textSize="20dip" />

 

            

                android:id="@+id/tab3"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Tab 3"

                android:textSize="20dip" />

        

    

 

 

 tabhostandbadgeview_第4张图片

 tabhostandbadgeview_第5张图片

 

tab_icon.xml

-------------------------------------------------------------------------------------------------------------------------------

    android:layout_width="fill_parent"

    android:layout_height="40dip"

    android:background="@drawable/tab"

    android:orientation="vertical" >

 

    

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:background="@drawable/tab_select"

        android:gravity="center"

        android:orientation="horizontal" >

 

        

            android:id="@+id/iv"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_gravity="center"

            android:paddingTop="5dp" />

 

        

            android:id="@+id/tv"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_gravity="center"

            android:gravity="center" />

    

 

 

 tabhostandbadgeview_第6张图片

 tabhostandbadgeview_第7张图片

 

tab_icon2.xml

-------------------------------------------------------------------------------------------------------------------------------

    android:layout_width="fill_parent"

    android:layout_height="40dip"

    android:background="@drawable/tab"

    android:orientation="vertical" >

 

    

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:background="@drawable/tab_select"

        android:gravity="center"

        android:orientation="vertical" >

 

        

            android:id="@+id/iv"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:layout_gravity="center"

            android:paddingTop="5dp" />

 

        

            android:id="@+id/tv"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_gravity="center"

            android:gravity="center" />

    

 

 

 tabhostandbadgeview_第8张图片

 tabhostandbadgeview_第9张图片

 

activity_main.xml

-------------------------------------------------------------------------------------------------------------------------------

    android:id="@+id/mtabs"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical" >

 

    

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:orientation="vertical" >

 

        

            android:id="@android:id/tabs"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_weight="0" >

        

 

        

            android:id="@android:id/tabcontent"

            android:layout_width="fill_parent"

            android:layout_height="fill_parent"

            android:layout_weight="1" >

 

            

                android:id="@+id/tab1"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Tab 1"

                android:textSize="20dip" />

 

            

                android:id="@+id/tab2"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Tab 2"

                android:textSize="20dip" />

 

            

                android:id="@+id/tab3"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Tab 3"

                android:textSize="20dip" />

        

    

 

 

 tabhostandbadgeview_第10张图片

 tabhostandbadgeview_第11张图片

 

MainActivity.java

-------------------------------------------------------------------------------------------------------------------------------

package com.tabhostandbadgeview;

 

import com.readystatesoftware.viewbadger.BadgeView;

 

import android.app.Activity;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.ImageView;

import android.widget.TabHost;

import android.widget.TextView;

 

/**

 * 

 * 项目名称:com.tabhostandbadgeview   

 * 类  名  称:MainActivity   

 * 类  描  述: TabHost导航菜单与BadgeView徽章视图的混合应用  

 * 创  建  人:fy   

 * 创建时间:2014-3-19 上午10:00:04   

 * Copyright (c) 方勇-版权所有

 */

public class MainActivity extends Activity {

 

/* TabHost导航菜单 */

private TabHost mTab;

 

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

initTabHost();

}

 

private void initTabHost() {

/* 最热导航菜单 */

View hot = (View) LayoutInflater.from(this).inflate(R.layout.tab_icon, null);

TextView home_tv = (TextView) hot.findViewById(R.id.tv);

home_tv.setText("最热");

ImageView home_iv = (ImageView) hot.findViewById(R.id.iv);

home_iv.setImageResource(R.drawable.tab_1);

 

/* 最新上架导航菜单 */

View latest = (View) LayoutInflater.from(this).inflate(R.layout.tab_icon, null);

TextView setting_tv = (TextView) latest.findViewById(R.id.tv);

setting_tv.setText("最新");

ImageView setting_iv = (ImageView) latest.findViewById(R.id.iv);

setting_iv.setImageResource(R.drawable.tab_2);

 

/* 推荐导航菜单 */

View ok = (View) LayoutInflater.from(this).inflate(R.layout.tab_icon2, null);

TextView ok_tv = (TextView) ok.findViewById(R.id.tv);

ok_tv.setText("推荐");

ImageView ok_iv = (ImageView) ok.findViewById(R.id.iv);

ok_iv.setImageResource(R.drawable.tab_3);

mTab = (TabHost) findViewById(R.id.mtabs);

mTab.setup();

 

mTab.addTab(mTab.newTabSpec("01").setIndicator(hot).setContent(R.id.tab1));

mTab.addTab(mTab.newTabSpec("02").setIndicator(latest).setContent(R.id.tab2));

mTab.addTab(mTab.newTabSpec("03").setIndicator(ok).setContent(R.id.tab3));

 

/* 徽章视图,停留在推荐导航菜单右上角 */

BadgeView badge = new BadgeView(this, ok_iv);

badge.setText("10");

badge.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);

badge.show();

}

}

  • tabhostandbadgeview_第12张图片
  • 大小: 40.4 KB
  • tabhostandbadgeview_第13张图片
  • 大小: 40.4 KB
  • tabhostandbadgeview_第14张图片
  • 大小: 39.8 KB
  • tabhostandbadgeview_第15张图片
  • 大小: 5.9 KB
  • tabhostandbadgeview_第16张图片
  • 大小: 11.2 KB
  • tabhostandbadgeview_第17张图片
  • 大小: 6.8 KB
  • tabhostandbadgeview_第18张图片
  • 大小: 3.5 KB
  • tabhostandbadgeview_第19张图片
  • 大小: 4.2 KB
  • tabhostandbadgeview_第20张图片
  • 大小: 7.2 KB
  • tabhostandbadgeview_第21张图片
  • 大小: 4.2 KB
  • tabhostandbadgeview_第22张图片
  • 大小: 7.5 KB
  • tabhostandbadgeview_第23张图片
  • 大小: 8.5 KB
  • com.tabhostandbadgeview.zip (1.5 MB)
  • 下载次数: 13
  • 查看图片附件

你可能感兴趣的:(android,浮动数字)