Android 在TabHost的TabSpec中显示XML设计时出现问题?
我设计了一个TabHost,它有3个TabSpec,所以我需要为每个TabSpec添加GridView,我为每个TabSpec创建了显示GridView的XML设计,并添加了如下所示: 创建选项卡主机:Android 在TabHost的TabSpec中显示XML设计时出现问题?,android,android-tabhost,Android,Android Tabhost,我设计了一个TabHost,它有3个TabSpec,所以我需要为每个TabSpec添加GridView,我为每个TabSpec创建了显示GridView的XML设计,并添加了如下所示: 创建选项卡主机: TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusabl
TabHost tabHost = getTabHost(); // The activity TabHost
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, Positions.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("positions").setIndicator("Positions",
res.getDrawable(R.drawable.buy))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, BuyPwr.class);
spec = tabHost.newTabSpec("buypwr").setIndicator("Buy Power",
res.getDrawable(R.drawable.buy))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Trades.class);
spec = tabHost.newTabSpec("trades").setIndicator("Trades",
res.getDrawable(R.drawable.buy))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
第一个TabSpec“位置”的代码
“posgrid.XML”的XML设计
我还在清单文件中添加了活动,如:
<activity android:name=".Positions" android:label="Pos"></activity>
所以我并没有得到任何错误,但“posgrid”设计并没有显示在POSTS标签中,请任何人帮助我
谢谢,
nag.可能的原因是一些标签中缺少布局高度和布局宽度,如上表行和下表行的TextView。嗨,Shailendra,我按照你说的那样尝试添加布局宽度和高度,但即使我没有得到。嗯,我找到了答案,我错误地声明了TabHost和FrameLayout,所以它没有显示出来。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:text="Current Position"
android:layout_width="100dp"
android:layout_column="0"
android:layout_weight="1"/>
<TextView android:text="Buy"
android:layout_width="30dp"
android:layout_column="1"
android:layout_weight="1">
</TextView>
<TextView android:text="Sell"
android:layout_width="30dp"
android:layout_column="2"
android:layout_weight="1">
</TextView>
</TableRow>
<ScrollView android:layout_height="120dp">
<TableLayout android:id="@+id/score_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:text="Al"
android:layout_width="100dp"
android:layout_column="0"
android:layout_weight="1">
</TextView>
<TextView android:text="1000"
android:layout_width="30dp"
android:layout_column="1"
android:layout_weight="1">
</TextView>
<TextView android:text="2"
android:layout_width="30dp"
android:layout_column="2"
android:layout_weight="1">
</TextView>
</TableRow>
</TableLayout>
</ScrollView>
</TableLayout>
</LinearLayout>
<activity android:name=".Positions" android:label="Pos"></activity>