简体   繁体   English

如何创建滚动标签?

[英]How to create scrollable tabs?

I am working to create scroll able tabs, please help me out, I am using below code, but not work for me 我正在创建可滚动的标签,请帮帮我,我正在使用以下代码,但不适用于我

   <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>

Please let me know specific answers 请让我知道具体答案

This Code work for 3.0 and higher versions : 此代码适用于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>

But not for lower versions,I need to make work for scrollable tabs for all devices 但不适用于较低版本,我需要为所有设备创建可滚动标签

This is works for version 2.2+ 这适用于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>

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

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