简体   繁体   English

如何在底部添加标签

[英]How to add tabs at bottom

I have a tabhost which contains three tabs, connected with three activities. 我有一个tabhost,其中包含三个选项卡,与三个活动相关联。 All three tabs are in the upper side. 所有三个选项卡都在上侧。 How can I make these three tabs at the bottom? 如何在底部显示这三个选项卡?

I found this, but there are still some problems. 我找到了,但是仍然存在一些问题。

This is my tabhost XML file: 这是我的tabhost XML文件:

<?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="fill_parent"
            android:layout_weight="1" />
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>
    </LinearLayout>
</TabHost>

In my TabActivity class, I have following code: 在我的TabActivity类中,我有以下代码:

setContentView(R.layout.tabs);

TabHost mTabHost = (TabHost)findViewById(android.R.id.tabhost);

mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(new Intent(AndroisTabViewActivity.this,TabActivity1.class)));

mTabHost.setCurrentTab(0);

There is one activity named TabActivity1 which I have also included in Manifest file. 清单文件中也包含一个名为TabActivity1的活动。 But it is showing the error: 但是它显示了错误:

Can't get the activity TabActivity1. 无法获得活动TabActivity1。

I assume you want to show "Tab" at bottom of the window, just try this: 我假设您想在窗口底部显示“制表符”,只需尝试以下操作:

<RelativeLayout
    android:layout_width="match_parent"
    android:id="@+id/linearLayout1"
    android:layout_height="match_parent">

    <TabWidget
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@android:id/tabs"
        android:layout_alignParentBottom="true">
    </TabWidget>

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

If you want to use the LinearLayout : 如果要使用LinearLayout

<?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="0dp"
            android:layout_weight="1" />
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</TabHost>

With this solution, the tab content will take no space firstly, the TabWidget will take its own space, then the remaining space will be given to the tab content . 使用此解决方案, tab content将首先不占用空间, TabWidget将占用其自己的空间,然后将剩余空间分配给tab content

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM