如何创建可滚动的标签?

时间:2013-07-22 07:10:39

标签: android

我正在创建滚动功能标签,请帮助我,我使用下面的代码,但不适合我

   <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">
<HorizontalScrollView
               android:layout_width="fill_parent"
               android:layout_height="wrap_content">
                <TabWidget
                    android:id="@android:id/tabs"
                   android:layout_width="fill_parent"
                    android:layout_height="wrap_content" /> 
</HorizontalScrollView>
<FrameLayout
               android:id="@android:id/tabcontent"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:padding="5dp" />
</LinearLayout>
</TabHost>

请让我知道具体答案

2 个答案:

答案 0 :(得分:3)

此代码适用于3.0及更高版本:

<?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="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
 <HorizontalScrollView android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                     android:fillViewport="true"
                     android:scrollbars="horizontal"

                   >
    <LinearLayout android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

          <TabWidget android:id="@android:id/tabs"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content"/>

        <FrameLayout android:id="@android:id/tabcontent"
                     android:layout_width="fill_parent"
                     android:layout_height="fill_parent" />
      </LinearLayout>
      </HorizontalScrollView>
      </LinearLayout>
      </TabHost>

但是对于较低版本,我需要为所有设备的可滚动标签工作

答案 1 :(得分:1)

这适用于版本2.2 +

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

    <TabHost
        android1:id="@android:id/tabhost"
        android1:layout_width="match_parent"
        android1:layout_height="match_parent" >
        <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
            <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
                <HorizontalScrollView android:scrollbars="none" android:layout_width="fill_parent" android:layout_height="wrap_content" android:fillViewport="true">
                    <TabWidget android:id="@android:id/tabs" 
                        android:layout_width="fill_parent" 
                        android:layout_height="wrap_content" 
                        android:layout_weight="0.0" 
                        android:background="@drawable/tab_bg_unselected"/>
                </HorizontalScrollView>
                <RelativeLayout 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_alignParentTop="true" />
                </RelativeLayout>
            </LinearLayout>
        </FrameLayout>
    </TabHost>

相关问题