0

タブレイアウトにスクロール機能があると思われるアプリケーションを開発しています。しかし、私はそれを実装する方法を本当に知りません。誰か助けてもらえますか? ページの上部にタブを追加してから、タブを水平方向にスクロールするつもりです。

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>

ここに画像の説明を入力

4

2 に答える 2

0

xml で使用<HorizontalScrollView>して水平スクロールを実現する

于 2013-10-25T06:44:55.803 に答える