Android项目--tabhost

所有牵扯到自定义布局的layout中尽量用RelativeLayout

在通讯录中如果像小米手机的UI那就是viewpager,在这里,我们做成静态的。通过tabhost来做。

1.布局

a) 直接用TabHost作为布局框架

b) 代码:

<?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="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_weight="0.0"
            android:background="@drawable/contact_tabhost" >
        </TabWidget>

    </RelativeLayout>

</TabHost>

 

FrameLayout中就是填充需要的布局

TabWidge是切换的响应式按钮,两者有着关联性的作用

2.设计

a) 像QQ,微信这样的客户端,应该也是tabhost做的吧。简单,明了,不用费太多的事,就能在一个布局框架中,创建出无数个布局。可同,可异

b) 定义一个ContactActivity extends TabActivity

c) 代码:

private void createTab(int img, String text, Intent intent) {
        mTabHost.addTab(mTabHost.newTabSpec(text)
                .setIndicator(createTabView(img, text)).setContent(intent));
    }

    private View createTabView(int img, String text) {
        View view = LayoutInflater.from(this).inflate(
                R.layout.contact_tab_indicator, null);
        ImageView iv = (ImageView) view.findViewById(R.id.iv_tab);
        TextView tv = (TextView) view.findViewById(R.id.tv_tab);
        iv.setImageResource(img);
        tv.setText(text);
        return view;
    }

 

3.功能

a) 需要三个布局来填充

b) 代码:

mTabHost = getTabHost();
        Intent intent1 = new Intent(this, ContactListActivity.class);
        createTab(R.drawable.contact, "通讯录", intent1);

        Intent intent2 = new Intent(this, ContactCalllog.class);
        createTab(R.drawable.logcall, "通话记录", intent2);

        Intent intent3 = new Intent(this, ContactMess.class);
        createTab(R.drawable.message, "短信", intent3);

        mTabHost.setCurrentTab(0);

 

 

转载于:https://www.cnblogs.com/qiuge227/p/3780531.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值