这是我的第一个选项卡式Android应用程序。我在androids网站上浏览了“ HelloTabWidget”应用程序,但是我不知道如何向选项卡添加内容。 FrameLayout将东西彼此堆叠在左上方(根据我的阅读)。我添加了几个textviews和一个imageView,但是它仅显示最后添加的项目。有没有一种方法可以使用线性布局而不是框架布局?如果没有,如何在选项卡中放置多个视图?与示例不同,我唯一要做的就是添加了第四个标签。在活动选项卡之一中,我插入了以下代码,以尝试显示多个项目:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the About tab");
setContentView(textview);
TextView textview2 = new TextView(this);
textview2.setText("About Test");
setContentView(textview2);
ImageView imgView = new ImageView(this);
imgView.setImageDrawable(getResources().getDrawable(R.drawable.header));
setContentView(imgView);
}
这是我遵循的示例的链接:
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
最佳答案
您的布局xml文件是什么?我用它,我可以在每个选项卡中堆叠几个textview。 TabActivity:
<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">
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<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" />
</LinearLayout>
</ScrollView>
</TabHost>
标签内的活动:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView android:id="@+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/textTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout>
我本人是新手,因此可能会有更好的方法。不过,这对我有用。