Android应用程序在某些设备上正确运行,并且某些设备应用程序崩溃

时间:2018-12-03 06:14:01

标签: android android-layout android-fragments

我的android应用程序在某些设备上正确运行,但是在某些设备上,它在片段上显示错误,某些功能正在运行,但是当我打开片段时,应用程序崩溃时,会出现以下错误。

  

android.view.InflateException:二进制XML文件第205行:二进制XML文件第205行:膨胀类错误

我的片段:

public class FragmentHouse extends Fragment {


    public FragmentHouse() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        context = getActivity();
        View rootView = inflater.inflate(R.layout.houses, container, false);




        fab_tenants = (FloatingActionButton) rootView.findViewById(R.id.fab_tenants);
        fab_tenants.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ActivityAddTenants.class);
                startActivity(intent);
            }
        });
        fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ActivityAddOwner.class);
                startActivity(intent);
            }
        });
        sp_hosue_details = (MaterialBetterSpinner) rootView.findViewById(R.id.sp_house_details);
        card_house = (CardView) rootView.findViewById(R.id.card_house);

        sp_house_type = (MaterialBetterSpinner) rootView.findViewById(R.id.sp_house_type);
        sp_direction_facing = (MaterialBetterSpinner) rootView.findViewById(R.id.sp_direction_facing);
        sp_gst_state = (MaterialBetterSpinner) rootView.findViewById(R.id.sp_gst_state);
        sp_parking_lots = (MaterialBetterSpinner) rootView.findViewById(R.id.sp_parking_lots);
        sp_my_staff = (MaterialBetterSpinner) rootView.findViewById(R.id.sp_my_staff);
        sp_my_documents = (MaterialBetterSpinner) rootView.findViewById(R.id.sp_my_documents);
        sp_others = (MaterialBetterSpinner) rootView.findViewById(R.id.sp_others);
        rv_owner = (RecyclerView) rootView.findViewById(R.id.rv_owner);
        rv_tenants = (RecyclerView) rootView.findViewById(R.id.rv_tenants);
        tv_owner = (TextView) rootView.findViewById(R.id.tv_owner);
        tv_owner_family = (TextView) rootView.findViewById(R.id.tv_owner_family);
        tv_tenants = (TextView) rootView.findViewById(R.id.tv_tenants);
        tv_tenants_family = (TextView) rootView.findViewById(R.id.tv_tenants_family);

        ll_my_house_details = (LinearLayout) rootView.findViewById(R.id.ll_my_house_details);
        ll_my_parking = (LinearLayout) rootView.findViewById(R.id.ll_my_parking);
        ll_gst_registration = (LinearLayout) rootView.findViewById(R.id.ll_gst_registration);
        ll_my_staff = (LinearLayout) rootView.findViewById(R.id.ll_my_staff);
        ll_my_documents = (LinearLayout) rootView.findViewById(R.id.ll_my_documents);
        ll_others = (LinearLayout) rootView.findViewById(R.id.ll_others);
        ll_registered_tenants = (LinearLayout) rootView.findViewById(R.id.ll_registered_tenants);
        ll_registered_owners = (LinearLayout) rootView.findViewById(R.id.ll_registered_owners);


        Functions.setAdapter(context, list, sp_hosue_details);
        Functions.setAdapter(context, house_type, sp_house_type);
        Functions.setAdapter(context, list, sp_direction_facing);
        Functions.setAdapter(context, gstState, sp_gst_state);
        Functions.setAdapter(context, list, sp_parking_lots);
        Functions.setAdapter(context, list, sp_my_staff);
        Functions.setAdapter(context, list, sp_my_documents);
        Functions.setAdapter(context, list, sp_others);
        final JSONObject responce = null;

return rootview;

}

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:orientation="vertical">


    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">


            <RelativeLayout
                android:layout_width="match_parent"

                android:layout_height="wrap_content">


                <ImageView
                    android:id="@+id/test_image"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="fitXY"
                    android:src="@drawable/background_image" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="10dp"
                        android:orientation="vertical">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Block H- 107"
                            android:textColor="#FFFFFF"
                            android:textStyle="bold" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="1 BHK | 1 BATHROOM | 800.00 sq.ft"
                            android:textColor="#fff"
                            android:textSize="12dp" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:orientation="vertical">

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginRight="7dp"
                            android:gravity="end"
                            android:padding="1dp"
                            android:text="₹ 3,000"
                            android:textColor="#cc6656"
                            android:textSize="18sp"
                            android:textStyle="bold" />

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginRight="7dp"
                            android:gravity="end"
                            android:padding="1dp"
                            android:text="Pending dues"
                            android:textColor="#fff" />
                    </LinearLayout>

                </LinearLayout>

            </RelativeLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8.0dip"
                android:gravity="center"
                android:orientation="vertical"
                android:visibility="gone">

                <View
                    android:layout_width="fill_parent"
                    android:layout_height="0.100000024dip"
                    android:alpha="0.5"
                    android:background="@android:color/black" />

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="30.0dip"
                    android:gravity="center"
                    android:orientation="horizontal"
                    android:weightSum="4.0">

                    <View
                        android:layout_width="0.100000024dip"
                        android:layout_height="fill_parent"
                        android:alpha="0.5"
                        android:background="@android:color/black" />

                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1.0"
                        android:gravity="center"
                        android:text="Jon Doe(Primary Contact)"
                        android:textSize="11.0sp"
                        android:textStyle="bold" />

                    <View
                        android:layout_width="0.100000024dip"
                        android:layout_height="fill_parent"
                        android:alpha="0.5"
                        android:background="@android:color/black" />

                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1.0"
                        android:gravity="center"
                        android:text="Owner(s)"
                        android:textSize="11.0sp"
                        android:textStyle="bold" />

                    <View
                        android:layout_width="0.100000024dip"
                        android:layout_height="fill_parent"
                        android:alpha="0.5"
                        android:background="@android:color/black" />

                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1.0"
                        android:gravity="center"
                        android:text="Tenant(s)"
                        android:textSize="11.0sp"
                        android:textStyle="bold" />

                    <View
                        android:layout_width="0.100000024dip"
                        android:layout_height="fill_parent"
                        android:alpha="0.5"
                        android:background="@android:color/black"
                        android:visibility="visible" />

                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1.0"
                        android:gravity="center"
                        android:text="House Details"
                        android:textSize="11.0sp"
                        android:textStyle="bold"
                        android:visibility="visible" />


                    <View
                        android:layout_width="0.100000024dip"
                        android:layout_height="fill_parent"
                        android:alpha="0.5"
                        android:background="@android:color/black" />
                </LinearLayout>

                <View
                    android:layout_width="fill_parent"
                    android:layout_height="0.100000024dip"
                    android:alpha="0.5"
                    android:background="@android:color/black" />
            </LinearLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.v7.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:foreground="?android:attr/selectableItemBackground"
                    app:cardBackgroundColor="@android:color/white"
                    app:cardCornerRadius="2dp"
                    app:cardElevation="7dp"
                    app:cardUseCompatPadding="true">


                    <android.support.design.widget.FloatingActionButton
                        android:id="@+id/fab"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|end"
                        android:layout_margin="@dimen/fab_margin"
                        android:backgroundTint="@color/colororange"
                        android:src="@mipmap/add"
                        android:visibility="gone"
                        app:fabSize="mini" />


                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"

                            android:orientation="horizontal">


                            <TableRow
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_margin="1dp"

                                android:background="#f4f3f3">

                                <TextView

                                    android:id="@+id/tv_owner"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:background="@android:color/darker_gray"
                                    android:gravity="center"
                                    android:padding="7dp"
                                    android:text="Owner(s)"
                                    android:textColor="#000" />

                                <TextView
                                    android:id="@+id/tv_owner_family"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_marginLeft="2dp"
                                    android:layout_marginRight="2dp"
                                    android:layout_weight="1"
                                    android:background="#fff"
                                    android:gravity="center"
                                    android:padding="7dp"
                                    android:text="Owner's Family"
                                    android:textColor="#000" />

                                <TextView
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:background="#fff"
                                    android:gravity="center"
                                    android:padding="7dp"
                                    android:text="Past Owner(s)"
                                    android:textColor="#000" />

                            </TableRow>


                        </LinearLayout>

                        <View
                            android:layout_width="match_parent"
                            android:layout_height="1dp"
                            android:background="#f2f2f2" />

                        <android.support.v7.widget.RecyclerView
                            android:id="@+id/rv_owner"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">

                        </android.support.v7.widget.RecyclerView>

                    </LinearLayout>

                </android.support.v7.widget.CardView>
            </RelativeLayout>


    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:0)

将此内容粘贴到XML中并检查是否存在问题

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:orientation="vertical">


<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerInParent="true">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


    <RelativeLayout
        android:layout_width="match_parent"

        android:layout_height="wrap_content">


        <ImageView
            android:id="@+id/test_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:src="@drawable/background_image" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Block H- 107"
                    android:textColor="#FFFFFF"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1 BHK | 1 BATHROOM | 800.00 sq.ft"
                    android:textColor="#fff"
                    android:textSize="12dp" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="7dp"
                    android:gravity="end"
                    android:padding="1dp"
                    android:text="₹ 3,000"
                    android:textColor="#cc6656"
                    android:textSize="18sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="7dp"
                    android:gravity="end"
                    android:padding="1dp"
                    android:text="Pending dues"
                    android:textColor="#fff" />
            </LinearLayout>

        </LinearLayout>

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8.0dip"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone">

        <View
            android:layout_width="fill_parent"
            android:layout_height="0.100000024dip"
            android:alpha="0.5"
            android:background="@android:color/black" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="30.0dip"
            android:gravity="center"
            android:orientation="horizontal"
            android:weightSum="4.0">

            <View
                android:layout_width="0.100000024dip"
                android:layout_height="fill_parent"
                android:alpha="0.5"
                android:background="@android:color/black" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1.0"
                android:gravity="center"
                android:text="Jon Doe(Primary Contact)"
                android:textSize="11.0sp"
                android:textStyle="bold" />

            <View
                android:layout_width="0.100000024dip"
                android:layout_height="fill_parent"
                android:alpha="0.5"
                android:background="@android:color/black" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1.0"
                android:gravity="center"
                android:text="Owner(s)"
                android:textSize="11.0sp"
                android:textStyle="bold" />

            <View
                android:layout_width="0.100000024dip"
                android:layout_height="fill_parent"
                android:alpha="0.5"
                android:background="@android:color/black" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1.0"
                android:gravity="center"
                android:text="Tenant(s)"
                android:textSize="11.0sp"
                android:textStyle="bold" />

            <View
                android:layout_width="0.100000024dip"
                android:layout_height="fill_parent"
                android:alpha="0.5"
                android:background="@android:color/black"
                android:visibility="visible" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1.0"
                android:gravity="center"
                android:text="House Details"
                android:textSize="11.0sp"
                android:textStyle="bold"
                android:visibility="visible" />


            <View
                android:layout_width="0.100000024dip"
                android:layout_height="fill_parent"
                android:alpha="0.5"
                android:background="@android:color/black" />
        </LinearLayout>

        <View
            android:layout_width="fill_parent"
            android:layout_height="0.100000024dip"
            android:alpha="0.5"
            android:background="@android:color/black" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:foreground="?android:attr/selectableItemBackground"
            app:cardBackgroundColor="@android:color/white"
            app:cardCornerRadius="2dp"
            app:cardElevation="7dp"
            app:cardUseCompatPadding="true">


            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|end"
                android:layout_margin="@dimen/fab_margin"
                android:backgroundTint="@color/colororange"
                android:src="@mipmap/add"
                android:visibility="gone"
                app:fabSize="mini" />


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"

                    android:orientation="horizontal">


                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="1dp"

                        android:background="#f4f3f3">

                        <TextView

                            android:id="@+id/tv_owner"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:background="@android:color/darker_gray"
                            android:gravity="center"
                            android:padding="7dp"
                            android:text="Owner(s)"
                            android:textColor="#000" />

                        <TextView
                            android:id="@+id/tv_owner_family"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginLeft="2dp"
                            android:layout_marginRight="2dp"
                            android:layout_weight="1"
                            android:background="#fff"
                            android:gravity="center"
                            android:padding="7dp"
                            android:text="Owner's Family"
                            android:textColor="#000" />

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:background="#fff"
                            android:gravity="center"
                            android:padding="7dp"
                            android:text="Past Owner(s)"
                            android:textColor="#000" />

                    </TableRow>


                </LinearLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#f2f2f2" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/rv_owner"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                </android.support.v7.widget.RecyclerView>

            </LinearLayout>

        </android.support.v7.widget.CardView>
    </RelativeLayout>

    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

问题我发现您忘了关闭LINEARLAYOUT标签