Android java.lang.IllegalStateException:FragmentTabHost的标记null没有已知的选项卡
呈现XML文件时出错。 它有FragmentTabHost、带垂直滚动视图的TabWidget和用于显示选项卡内容的FrameLayout。是的,我用垂直标签代替水平标签 下面是布局文件Android java.lang.IllegalStateException:FragmentTabHost的标记null没有已知的选项卡,android,android-layout,Android,Android Layout,呈现XML文件时出错。 它有FragmentTabHost、带垂直滚动视图的TabWidget和用于显示选项卡内容的FrameLayout。是的,我用垂直标签代替水平标签 下面是布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.andro
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background2"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<ScrollView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.7" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/standard_height"
android:orientation="horizontal"
android:weightSum="1">
<com.custom.FontButton
android:id="@+id/btn_clear"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:background="@color/toolbar"
android:minHeight="@dimen/standard_height"
android:text="CLEAR"
android:textColor="@color/background"
android:textSize="@dimen/font_18"
app:customFont="@string/font_regular" />
<com.custom.FontButton
android:id="@+id/btn_apply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:background="@color/button"
android:elevation="5dp"
android:minHeight="@dimen/standard_height"
android:text="APPLY"
android:textColor="@color/background"
android:textSize="@dimen/font_18"
app:customFont="@string/font_regular" />
</LinearLayout>
</LinearLayout>
附言:我读过其他帖子,但没有一篇是有效的,所以请不要将此标记为重复
编辑:找到解决方案
FragmentTabHost
的问题在于,默认情况下,方向设置为TabWidget.HORIZONTAL
,并且不能通过XML修改,这就是为什么垂直滚动出现非法状态异常的原因。
要在片段
或活动
类中克服此问题,我们需要手动设置方向。查看片段以设置方向
TabWidget.setOrientation(TabWidget.VERTICAL);
一旦完成,您就不再犯错误了
TabWidget.setOrientation(TabWidget.VERTICAL);