MockView cannot be added to android.view.ViewGroup in xml

When checking in graphical layout, I get this error:

Exception thrown on rendering: com.android.layoutlib.bridge.MockView cannot be dropped android.view.ViewGroup

Below I posted my activity_main.xml code:

activity_main.xml:

 <?xml version="1.0" encoding="utf-8"?>

    <android.support.v4.widget.DrawerLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TextView
            android:id="@+id/textviewHeading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"
            android:fontFamily="fonts/Dosis.otf"
            android:text="@string/heading_chapter"
            android:textSize="25dp"
            android:visibility="gone" />

        <ListView
            android:id="@+id/listviewChapters"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/imageviewBanner"
            android:layout_below="@+id/textviewHeading"
            android:layout_marginTop="5dp" >
        </ListView>

        <ImageView
            android:id="@+id/imageviewBanner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/banner"
            android:visibility="invisible" />
    </RelativeLayout>

    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"        
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background"/>

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

      

+3


source to share


4 answers


This error occurred due to incorrect implementation of the box layout. I am putting three straight layouts in the drawer layout where the error will occur. According to google doc he took two layouts directly.

In the drawer layout, if I placed two straight layouts solved the problem. So I am using the frame layout as the parent layout below the Drawer Layout and then finally add a list view to display the navigation drawer.



activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <RelativeLayout
            android:id="@+id/container"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/textviewHeading"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:fontFamily="fonts/Dosis.otf"
                android:text="@string/heading_chapter"
                android:textSize="25sp"
                android:visibility="gone" />

            <ListView
                android:id="@+id/listviewChapters"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@+id/imageviewBanner"
                android:layout_below="@+id/textviewHeading"
                android:layout_marginTop="5dp" >
            </ListView>

            <ImageView
                android:id="@+id/imageviewBanner"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:src="@drawable/banner"
                android:visibility="invisible" />
        </RelativeLayout>
    </FrameLayout>

    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/list_background"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" />

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

      

+2


source


I found this issue in my project and then added the support.v4.jar file to my project, after which it solved my problem, so I think you can try this.



+2


source


use this

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.sun_soft.app_maker_new.MainActivity"
        tools:ignore="MergeRootFrame" />

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#ffffff"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

    <ListView
        android:id="@+id/right_drawer"
        android:layout_width="@dimen/paanelsize"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:background="#ffffff"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

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

Run codeHide result


and then you will have to reference the list in mainactivity and have to make an adapter and inflate the view for the listitem.

I think that in your code you are wrong throwing some kind of view. please post the code.

0


source


I would suggest you check the resources listed in your layout .

In my case, I made the mistake of saving the psd file as a png file. When this "bad" png file is referenced in my layout, Eclipse ends up with this error, i.e.

Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.widget.ImageView

      

Simply because the png file referenced in the ImageView was essentially a psd file, i.e .:

android:src="@drawable/my_psd_file_with_wrong_png_extension"

      

Hope it helps.

0


source







All Articles