0

こんにちは私はAndroidアプリをセットアップしていて、タブ付きのインターフェースを使用しています。Gridviewチュートリアルのように、テキストベースのタブ(About)、Webkitタブ(Store)、画像のgridviewタブ(Gallery)の3つのタブが欲しいです。

テキストとWebkitタブは正常に機能していますが、タブ内でグリッドビューをフォーマットするための最良の方法がわかりません。例としてタブ付きインターフェースtutrialを使用して、メインクラスのonCreate()イベント内でタブのコンテンツを宣言しています。

public class Woodroid extends TabActivity  {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        tabHost.setCurrentTab(0);

        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, AboutActivity.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("about").setIndicator("",
                          res.getDrawable(R.drawable.ic_tab_about))
                      .setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, StoreActivity.class);
        spec = tabHost.newTabSpec("store").setIndicator("Store",
                res.getDrawable(R.drawable.ic_tab_store))
            .setContent(intent);
        tabHost.addTab(spec);


        intent = new Intent().setClass(this, GalleryActivity.class);
        spec = tabHost.newTabSpec("gallery").setIndicator("Gallery",
                          res.getDrawable(R.drawable.ic_tab_gallery))
                      .setContent(intent);
        tabHost.addTab(spec);


        tabHost.setCurrentTab(0);
    }
}

したがって、GalleryActivity.javaには次のものがあります

public class GalleryActivity extends Activity {
  public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

            GridView gridview = new GridView(this);
            gridview.setAdapter(new ImageAdapter(this));

            setContentView(gridview);
     }
}

これは、gridviewチュートリアルからの解釈です。欠けているのは、グリッドビューのレイアウト定義です。のような属性のいくつかを強制できるようです gridview.setNumColumns(3); が、それでは、gridviewバージョンの/layout/main.xmlからのより柔軟に見える同等のものは許可されません。

android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
4

1 に答える 1

0

必ずFrameLayoutを使用してください。タブ付きの例を参照してください。fill_parentの代わりにandroid:layout_width = "WRAP_CONTENT"を設定してから、各オブジェクト要素の重力と重みを希望どおりになるまで試してください。

于 2010-12-02T15:54:14.387 に答える