こんにちは私はアンドロイドアプリを設定しており、タブ付きのインターフェースを使用しています。 Gridview tutorialのような3つのタブ、テキストベースのタブ(About)、Webkitタブ(Store)、画像のGridviewタブ(Gallery)が必要です。タブ付きレイアウト内にAndroidグリッドビューを表示するには
私はテキストとWebkitのタブは正常に動作していますが、タブ内のグリッドビューをフォーマットする最適な方法を理解できません。 tabbed interface 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に、私はGridViewのチュートリアルからの解釈である以下の
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);
などの属性の一部を強制することができそうですが、それが
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
これはコンテンツをラップする作業です。ありがとう!しかし、他の要素がすべてのタブに共通ではありません。私はデフォルトのイメージサイズ、列の幅などを明示的にJavaではなくxmlに設定するといいですか? – Lloyd
はい、私はそれらをjavaに入れてXMLに入れないのが最善の方法です。 –