【问题标题】:Android InflateException: Binary XML file line #178: Error inflating class fragmentAndroid InflateException: Binary XML file line #178: Error inflating class fragment
【发布时间】:2014-07-04 18:43:49
【问题描述】:

我收到一个 Inflate Exception 错误,正在膨胀类片段

这是我收到的错误 InflateException: Binary XML file line #178: Error inflating class fragment

问题在于片段的起始行

   <RelativeLayout
            android:id="@+id/lay_map"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginTop="8dp"
            android:layout_weight="0.4" >
            <fragment
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_centerInParent="true"
                android:layout_height="wrap_content"
                android:name="com.google.android.gms.maps.MapFragment" />
        </RelativeLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.08"
    android:background="@drawable/bg_titlebar"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingLeft="6dp"
    android:paddingRight="6dp" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.4"
        android:gravity="left"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/btn_locationDetails_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_prev" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        android:gravity="center" >

        <ImageView
            android:id="@+id/img_mark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"
            android:scaleType="fitCenter" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.4"
        android:gravity="right"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/btn_location"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_location" />

        <ImageView
            android:id="@+id/btn_users"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_users" />

        <ImageView
            android:id="@+id/btn_chatting"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_chatting" />
    </LinearLayout>
</LinearLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.92"
    android:background="#e0e0e0" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="15dp"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.2"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="0.4"
                android:gravity="center" >

                <ImageView
                    android:id="@+id/img_details"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:scaleType="fitCenter" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginBottom="6dp"
                android:layout_marginLeft="6dp"
                android:layout_weight="0.6"
                android:gravity="center_vertical"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/txt_details_category"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:gravity="center_vertical"
                    android:singleLine="true"
                    android:text="ADAM RESTURANT"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="#106c61"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/txt_details_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:text="3222 MAIN ST"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#106c61"
                    android:visibility="gone" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="center_vertical"
            android:layout_weight="0.1"
            android:gravity="center" >

            <ImageView
                android:id="@+id/btn_details_checkin"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/btn_checkin"
                android:scaleType="fitCenter" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginLeft="6dp"
            android:layout_marginTop="6dp"
            android:layout_weight="0.1"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/location_service"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#6f7179"
                android:textStyle="bold" />
        </LinearLayout>

        <RelativeLayout
            android:id="@+id/lay_map"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginTop="8dp"
            android:layout_weight="0.4" >
            <fragment
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_centerInParent="true"
                android:layout_height="wrap_content"
                android:name="com.google.android.gms.maps.MapFragment" />
        </RelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="center_vertical"
            android:layout_margin="6dp"
            android:layout_weight="0.1"
            android:gravity="center" >

            <ImageView
                android:id="@+id/btn_details_direction"
                android:layout_width="match_parent"
                android:layout_marginTop="6dp"
                android:layout_height="wrap_content"
                android:background="@drawable/btn_direction"
                android:scaleType="fitCenter" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginLeft="6dp"
            android:layout_marginTop="6dp"
            android:layout_weight="0.1"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/location_direction"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#6f7179"
                android:textStyle="bold" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >

        <include
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/location_info_panel" />
    </LinearLayout>
</RelativeLayout>

【问题讨论】:

  • 向我展示您使用此 mapFragment 的清单和活动。
  • 没有 ScrollView 怎么能管理尽可能多的视图?

标签: android android-layout


【解决方案1】:

您的最低 sdk 和目标 sdk 版本是多少?我不太确定,但我能想象的唯一错误是,您的 minSDK/targetSDK 没有针对 min API12。如果你想用 MapFragment 开发,使用最低目标 API 12,如果你想在更低的 API 上开发,那么你必须使用 SupportMapFragment:

     android:name="com.google.android.gms.maps.SupportMapFragment"

并包含库。有关详细信息,请参阅此:

http://developer.android.com/reference/com/google/android/gms/maps/MapFragment.html

http://developer.android.com/reference/com/google/android/gms/maps/SupportMapFragment.html

【讨论】:

    猜你喜欢
    • 2013-03-01
    • 2013-04-25
    • 2014-01-13
    • 2016-10-03
    • 2014-10-31
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    相关资源
    最近更新 更多