无法将MockView强制转换为xml中的android.view.ViewGroup [英] MockView cannot be cast to android.view.ViewGroup in xml
问题描述
在检查图形布局时出现此错误:
While checking in the graphical layout I am getting this error:
在渲染过程中引发异常: com.android.layoutlib.bridge.MockView无法转换为 android.view.ViewGroup
Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
在下面,我发布了activity_main.xml代码:
Below I am posted my activity_main.xml codes:
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>
推荐答案
发生此错误是由于抽屉布局的错误实现. 我将三个直接布局放置到抽屉布局中会发生错误.根据Google文档,它直接采用了两种布局.
This Error was occurred because of wrong implementation of the drawer layout. I place a three direct layout to Drawer layout the error would be occurring. As per the Google document, It took the two layout directly.
在抽屉布局"中,如果我放置两个直接布局,则可以解决此问题.这就是为什么我将框架布局"用作抽屉布局"下面的父布局,然后最终添加一个列表视图"以显示导航抽屉的原因.
In Drawer Layout, If I place a two direct Layout solved the problem. That's why I am using the Frame Layout as a parent layout below Drawer Layout then finally add a List View to show 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>
这篇关于无法将MockView强制转换为xml中的android.view.ViewGroup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!