Android Studio:无法在GridLayout上添加视图。安卓/浏览/搜索$ OnUnhandledKeyEventListener
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Studio:无法在GridLayout上添加视图。安卓/浏览/搜索$ OnUnhandledKeyEventListener相关的知识,希望对你有一定的参考价值。
我一直在努力解决这个问题好几个小时。为什么会这样?我正在关注一个网站上的课程(不确定我是否可以提及),一切都应该完美无缺,除非它不适合我。基本上,我正在尝试做的是“连接四”游戏,我想使用GridLayout并在其中添加ImageViews。当我尝试将ImageViews添加到gridLayout时,它们没有显示。它们“存在”,但并未真正展示。到目前为止我尝试了什么:
- 改变布局的高度和宽度
- 玩弄背景,能见度
- 谷歌搜索出这个问题。
- 向gridlayout添加垂直方向
- 从头再创造一切
- “使缓存无效/重新启动......”
Stack Trace java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:180) at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:61) at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:118) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:213) at android.support.v7.widget.GridLayout.isLayoutRtlCompat(GridLayout.java:679) at android.support.v7.widget.GridLayout.onLayout_Original(GridLayout.java:1082) at android.support.v7.widget.GridLayout.onLayout(GridLayout.java) at android.view.View.layout_Original(View.java:19659) at android.view.View_Delegate.layout(View_Delegate.java:91) at android.view.View.layout(View.java:19645) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.support.constraint.ConstraintLayout.onLayout_Original(ConstraintLayout.java:1858) at android.support.constraint.ConstraintLayout.onLayout(ConstraintLayout.java) at android.view.View.layout_Original(View.java:19659) at android.view.View_Delegate.layout(View_Delegate.java:91) at android.view.View.layout(View.java:19645) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout_Original(View.java:19659) at android.view.View_Delegate.layout(View_Delegate.java:91) at android.view.View.layout(View.java:19645) at android.view.ViewGroup.layout(ViewGroup.java:6075) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083) at android.view.View.layout_Original(View.java:19659) at android.view.View_Delegate.layout(View_Delegate.java:91) at android.view.View.layout(View.java:19645) at android.view.ViewGroup.layout(ViewGroup.java:6075) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:346) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384) at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:544) at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:678) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
activity_main.xml中<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.GridLayout android:layout_width="368dp" android:layout_height="359dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:background="@drawable/board2" android:visibility="visible" app:columnCount="3" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.6" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="1.0" app:rowCount="3"> <ImageView android:id="@+id/imageView" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/red" android:visibility="visible" app:srcCompat="@drawable/red" /> </android.support.v7.widget.GridLayout>
答案
我是Android的新手我也遇到了同样的错误,但我发现网格布局的一个简单方法是尝试使用基本的<GridLayout>
标签而不是<android.support.v7.widget.GridLayout>
便宜的方式......
以上是关于Android Studio:无法在GridLayout上添加视图。安卓/浏览/搜索$ OnUnhandledKeyEventListener的主要内容,如果未能解决你的问题,请参考以下文章
无法按照 Google“入门”页面中的说明在 Android Studio 中添加地图; Android Studio 报错
Android:无法在 android studio 中打开 eclipse 项目