关于两个Fragment布局报错Error inflating class fragment的解决方法

来源:互联网 发布:我的心时刻牵挂着网络 编辑:程序博客网 时间:2024/05/01 08:55


xml源代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
   
    <FrameLayout
        android:id="@+id/main_titles"
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight="1" />


    <FrameLayout
        android:id="@+id/main_details"
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight="4" />


</LinearLayout>


运行后报错: android.view.InflateException: Binary XML file line #4: Error inflating class fragment


解决方法:在linearlayout中设置上下文

  tools:context=".*********" 

星号为调用两个fragment的Activity。


0 0
原创粉丝点击