Java 水平滚动功能

Java 水平滚动功能,java,android,Java,Android,我正在开发一个应用程序,它应该在选项卡布局上具有滚动功能。但我真的不知道如何实施它,有人能帮忙吗?我打算在页面顶部添加更多选项卡,然后水平滚动这些选项卡 java代码 import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.widget.TabHost; im

我正在开发一个应用程序,它应该在选项卡布局上具有滚动功能。但我真的不知道如何实施它,有人能帮忙吗?我打算在页面顶部添加更多选项卡,然后水平滚动这些选项卡

java代码

 import android.app.TabActivity;
 import android.content.Intent;
 import android.content.res.Resources;
 import android.os.Bundle;
 import android.widget.TabHost;
 import android.widget.TabHost.TabSpec;

 public class MainActivity extends TabActivity {

 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 Resources ressources = getResources(); 
 TabHost tabHost = getTabHost(); 

 // Livingroom tab
 Intent intentAndroid = new Intent().setClass(this, livingroomActivity.class);
 TabSpec tabSpecAndroid = tabHost
 .newTabSpec("livingroom")
 .setIndicator("", ressources.getDrawable(R.drawable.Living))
 .setContent(intentLiving);

 // dadnmom tab
 Intent intentApple = new Intent().setClass(this, dadmomActivity.class);
 TabSpec tabSpecApple = tabHost
 .newTabSpec("Dadmom")
 .setIndicator("", ressources.getDrawable(R.drawable.icon_apple_config))
 .setContent(intentdadmom);

 // myroom tab
 Intent intentWindows = new Intent().setClass(this, myroomActivity.class);
 TabSpec tabSpecWindows = tabHost
 .newTabSpec("myroom")
 .setIndicator("", ressources.getDrawable(R.drawable.icon_windows_config))
 .setContent(intentmyroom);

 // kitchen room tab
 Intent intentBerry = new Intent().setClass(this, kitchenActivity.class);
 TabSpec tabSpecBerry = tabHost
 .newTabSpec("kitchen")
 .setIndicator("", ressources.getDrawable(R.drawable.icon_blackberry_config))
 .setContent(intentkitchen);

 // add all tabs 
 tabHost.addTab(tabSpecliving);
 tabHost.addTab(tabSpecdadmom);
 tabHost.addTab(tabSpecmyroom);
 tabHost.addTab(tabSpeckitchen);

 //set Windows tab as default (zero based)
 tabHost.setCurrentTab(0);
 }

 }
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"
 android:padding="5dp">
 <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"
 android:padding="5dp" />
 </LinearLayout>
 </TabHost>


在xml中使用
来实现水平滚动

在xml中使用
水平滚动视图

例如


希望这能奏效

<HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/darker_gray" />
        </HorizontalScrollView>