我正在开发一个假设在选项卡布局上具有滚动功能的应用程序。但我真的不知道如何实现它,有人可以帮忙吗?我打算在页面顶部添加更多选项卡,然后水平滚动选项卡。
爪哇代码
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>