gpt4 book ai didi

java - 渲染时出现异常 : com. android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup

转载 作者:太空狗 更新时间:2023-10-29 14:16:30 25 4
gpt4 key购买 nike

我正在 eclipse 上开发这个 android 项目。我在主要 Activity 上创建了两个 gridLayouts 和一个文本字段。它不断在窗口中显示此警告“无法实例化以下类:- android.support.v7.widget.GridLayout(公开课,显示错误日志)”但是当我尝试向 GridLayout 添加一个按钮时, Activity 卡住,现在它显示以下消息“注意:该项目包含 Java 编译错误,这可能会导致自定义 View 渲染失败。首先修复编译问题。

渲染期间出现异常:com.android.layoutlib.bridge.MockView 无法转换为 android.view.ViewGroup异常详细信息记录在 Window > Show View > Error Log 中无法实例化以下类:- android.support.v7.widget.GridLayout(公开课,显示错误日志)”我的 xml 文件是:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context=".MainActivity"
xmlns:app="http://schemas.android.com/apk/res/com.example.simple_calculator">

<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="94dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />

<android.support.v7.widget.GridLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="232dp"
android:layout_marginTop="100dp" >
</android.support.v7.widget.GridLayout>

<android.support.v7.widget.GridLayout
android:layout_width="232dp"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
app:columnCount="1" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_column="0"
app:layout_gravity="left|top"
app:layout_row="0"
android:text="Button" />

</android.support.v7.widget.GridLayout>
</FrameLayout>

我已经尝试导入 android-sdk-[platform]/extras/android/support/v7/gridlayout,但仍然出现同样的错误。

最佳答案

尝试使用下面的代码(我修改了你的代码,没有添加任何其他东西):

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context=".MainActivity"
xmlns:app="http://schemas.android.com/apk/res/com.example.simple_calculator">

<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="94dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />

<GridLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="232dp"
android:layout_marginTop="100dp" >
</GridLayout>

<GridLayout
android:layout_width="232dp"
android:layout_height="match_parent"
android:layout_marginTop="100dp"

>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"


android:text="Button" />

</GridLayout>
</FrameLayout>

在此代码中,网格布局和 app:column 和重力部分已修改,报告的异常已更正,代码工作正常,对于布局规则,请检查以下链接:

http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/

希望这有助于解决问题:)

最好的问候

关于java - 渲染时出现异常 : com. android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21459891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com