Android 不显示选项卡:
我是android编程新手,需要一个高级用户来检查我的工作。由于某些原因,当我运行这个应用程序时,我会得到一个空白屏幕,而不是我想要的两个选项卡。非常感谢 MainActivity.javaAndroid 不显示选项卡:,android,Android,我是android编程新手,需要一个高级用户来检查我的工作。由于某些原因,当我运行这个应用程序时,我会得到一个空白屏幕,而不是我想要的两个选项卡。非常感谢 MainActivity.java package com.example.storeitemfinder3; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.TabHost; imp
package com.example.storeitemfinder3;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(R.layout.tab1);
spec1.setIndicator("Tab 1");
TabSpec spec2=tabHost.newTabSpec("Tab 2");
spec2.setIndicator("Tab 2");
spec2.setContent(R.layout.tab2);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
活动\u main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<include layout="@layout/tab1" />
<include layout="@layout/tab2" />
</TabHost>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
android:layout_height="fill_parent"
android:layout_height="fill_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
tab1.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<include layout="@layout/tab1" />
<include layout="@layout/tab2" />
</TabHost>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
android:layout_height="fill_parent"
android:layout_height="fill_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
////android:checked=“true”
tab2.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<include layout="@layout/tab1" />
<include layout="@layout/tab2" />
</TabHost>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
android:layout_height="fill_parent"
android:layout_height="fill_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
可能是因为两者都是全屏的,所以可能隐藏了选项卡,只是尝试检查布局 tab1.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<include layout="@layout/tab1" />
<include layout="@layout/tab2" />
</TabHost>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
android:layout_height="fill_parent"
android:layout_height="fill_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
tab2.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<include layout="@layout/tab1" />
<include layout="@layout/tab2" />
</TabHost>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
android:layout_height="fill_parent"
android:layout_height="fill_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
所以换成这个
tab1.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<include layout="@layout/tab1" />
<include layout="@layout/tab2" />
</TabHost>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
android:layout_height="fill_parent"
android:layout_height="fill_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
////android:checked=“true”
tab2.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<include layout="@layout/tab1" />
<include layout="@layout/tab2" />
</TabHost>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
android:layout_height="fill_parent"
android:layout_height="fill_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
<?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="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>
这是从以下内容中提取的:
选项卡式窗口视图的容器。此对象包含两个子对象:a
用户单击以选择特定选项卡的选项卡标签集,以及
显示该页面内容的FrameLayout对象。这个
单个元素通常使用此容器进行控制
对象,而不是在子元素本身上设置值
您需要有一个
FrameLayout
作为TabHost
的子项,答案上有一个复选按钮(在该问题的投票下面)。通过单击它,您可以将此答案设置为回答您问题的答案。如果这是解决你问题的答案,那么就这样做。如果没有,请选择对您有帮助的答案。@user2749364是否有效如果有效,则您应评分并接受