如何将标签移到底部?

时间:2013-02-08 19:26:39

标签: android android-tabhost

我尝试使用TabHost在Android中制作带有两个标签的tabview。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TabHost
        android1:id="@+id/tabhost"
        android1:layout_width="match_parent"
        android1:layout_height="match_parent" >

        <LinearLayout
            android1:layout_width="match_parent"
            android1:layout_height="match_parent"
            android1:orientation="vertical" >

            <TabWidget
                android1:id="@android:id/tabs"
                android1:layout_width="match_parent"
                android1:layout_height="wrap_content"
                android1:gravity="bottom" >
            </TabWidget>

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

                <LinearLayout
                    android1:id="@+id/privacy_tab"
                    android1:layout_width="match_parent"
                    android1:layout_height="match_parent" >

                    <WebView
                        android1:id="@+id/privacy_web_view"
                        android1:layout_width="match_parent"
                        android1:layout_height="match_parent" />
                </LinearLayout>

                <LinearLayout
                    android1:id="@+id/about_tab"
                    android1:layout_width="match_parent"
                    android1:layout_height="match_parent" >

                    <WebView
                        android1:id="@+id/about_web_view"
                        android1:layout_width="match_parent"
                        android1:layout_height="match_parent" />
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>

</LinearLayout>

如上所示,它是包含tabhost的xml。 但是,我想在布局的底部制作选项卡。 我怎么能这样做?

3 个答案:

答案 0 :(得分:0)

在你发布之前,你有google搜索吗?


Android: Tabs at the BOTTOM

How to set tab bar at the bottom in android?

但是,不要使用底部标签,这不是android风格!
http://developer.android.com/design/patterns/pure-android.html

答案 1 :(得分:0)

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

    <LinearLayout  xmlns:android1="http://schemas.android.com/apk/res/android"
        android1:layout_width="match_parent"
        android1:layout_height="match_parent"
        android1:orientation="vertical" >
        <FrameLayout
            android1:id="@android:id/tabcontent"
            android1:layout_width="match_parent"
            android1:layout_height="wrap_content" >

            <LinearLayout
                android1:id="@+id/privacy_tab"
                android1:layout_width="match_parent"
                android1:layout_height="match_parent" >

                <WebView
                    android1:id="@+id/privacy_web_view"
                    android1:layout_width="match_parent"
                    android1:layout_height="match_parent" />
            </LinearLayout>

            <LinearLayout
                android1:id="@+id/about_tab"
                android1:layout_width="match_parent"
                android1:layout_height="match_parent" >

                <WebView
                    android1:id="@+id/about_web_view"
                    android1:layout_width="match_parent"
                    android1:layout_height="match_parent" />
            </LinearLayout>
        </FrameLayout>
       <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="horizontal" />
    </LinearLayout>
</TabHost>

答案 2 :(得分:0)

我刚才回答了类似的问题。使Tabs粘在底部的唯一方法是伪造它!

首先将文件名创建为footer.xml 将此代码放入其中。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="78dp"
    android:layout_gravity="bottom"
    android:gravity="bottom"
 android:layout_weight=".15"
    android:orientation="horizontal"
    android:background="@drawable/actionbar_dark_background_tile" >
    <ImageView
        android:id="@+id/lborder"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/overlay" />
    <ImageView
        android:id="@+id/unknown"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/notcolor" />
    <ImageView
        android:id="@+id/open"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/openit"
        />
    <ImageView
        android:id="@+id/color"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/colored" />
        <ImageView
        android:id="@+id/rborder"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/frames"
        android:layout_weight=".14" />


</LinearLayout>  

然后创建 header.xml 并将此代码放入其中。:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="@dimen/action_bar_height"
    android:layout_gravity="top"
    android:baselineAligned="true"
    android:orientation="horizontal"
    android:background="@drawable/actionbar_dark_background_tile" >
    <ImageView
        android:id="@+id/contact"
        android:layout_width="37dp"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:layout_weight=".18"
        android:scaleType="fitCenter"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/logo"/>

    <ImageView
        android:id="@+id/share"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/share" />

    <ImageView
        android:id="@+id/save"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/save" />

    <ImageView
        android:id="@+id/set"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/set" />

    <ImageView
        android:id="@+id/fix"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/light" />

    <ImageView
        android:id="@+id/rotate"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/ic_menu_rotate" />

    <ImageView
        android:id="@+id/stock"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".14"
        android:background="@drawable/action_bar_left_button"
        android:src="@drawable/stock" />

</LinearLayout>

然后在你的main_activity.xml中并将此代码放入其中: -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:id="@+id/relt"
android:background="@drawable/background" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="78dp"
    android:id="@+id/down"
    android:layout_alignParentBottom="true" >

    <include
        android:layout_width="fill_parent"
        android:layout_height="78dp"
        layout="@layout/footer" >
    </include>
</LinearLayout>
<ImageView
    android:id="@+id/view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/down"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/inc"
   >  
    </ImageView> 
    <include layout="@layout/header"
        android:id="@+id/inc"
        android:layout_width="fill_parent"
        android:layout_height="50dp"></include> 

快乐的编码:)

相关问题