这是我用Android选项卡获得的奇怪行为。或者,也许模拟器是责备!在下面你有用于布局的XML。Android Tabs问题
为每个选项卡单独设计的布局是res/layout/tab1.xml和res/layout/tab2.xml ...并且一切似乎都能正常工作,除非在绘制时重叠选项卡。如果我选择TAB1,一切看起来都很正常,但如果我选择TAB2,它只是绘制tab1布局。如果我回到tab1然后再一切看起来很正常。
那么为什么它会从tab1中绘制布局,而不是从黑色/空白屏幕开始?在绘制标签2的布局和内容之前,TabWidget是否应该处理这些情况并调用clear()方法或其他东西?
我正在模拟Android 2.2(API级别8)的机器。
<?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">
<include layout="@layout/tab1" />
<include layout="@layout/tab2" />
</FrameLayout>
</LinearLayout>
</TabHost>
编辑:根据要求,我会添加TAB2布局基本上是一个空白的屏幕!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
那么,为什么,如果我切换到TAB2任何想法...它只是借鉴(添加字符串)在TAB1的控件(按钮等),并没有从空白/黑色屏幕开始?
你也可以发布tab2的布局吗?也许它的宽度和高度设置为wrap_content? – Adinia 2011-03-08 10:18:33
第二个选项卡只包含一个我正在写东西的空白屏幕。所以它只包含一个线性布局。但文本出现在第一个选项卡的按钮上......而不是带有一些文本的空白黑屏。虽然我会尝试你所说的,但从wrap context改为fill_parent可能会做一些有用的事情。 – Tibbers 2011-03-08 12:09:59