简体   繁体   English

Android布局:看不到布局视图

[英]Android layout: Cannot see the layout view

I just installed Android Studio 3 Preview Canary 6. I could not get a preview of the xml layout in activity_main.xml because of the following errors: 我刚刚安装了Android Studio 3预览版Canary6。由于以下错误,我无法在activity_main.xml中获得xml布局的预览:

  1. Render Problem 渲染问题
  2. Failed to instantiate one or more classes 无法实例化一个或多个类

This also happened when I installed Canary 5. I thought that upgrading to Canary 6 would solve this issue but it didn't. 当我安装Canary 5时,也发生了这种情况。我认为升级到Canary 6可以解决此问题,但事实并非如此。 Please help me fix it so I could start building my apps. 请帮助我修复它,以便我可以开始构建我的应用程序。

我目前的情况

Here is my XML: 这是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.companyname.zooapp.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

You shouldn't post bugs of the Canary version of the Android Studio on StackOverflow. 您不应该在StackOverflow上发布Canary版本的Android Studio的错误。 These type of questions and help you should receive in the android studio bugtracker. 这些类型的问题和帮助,您应该在android studio bugtracker中收到。

Note that it is called a Canary version since it is full of bugs, and Google knows that, and they even know the bugs and explicitly say what are the bugs they know. 请注意,它被称为Canary版本,因为其中包含许多错误,Google知道这一点,他们甚至知道这些错误,并明确说出他们知道的错误是什么。

Check here to see the releases and bugs . 在此处查看发行版和错误

First of all make sure you are using the latest version ConstraintLayout dependency. 首先,请确保您使用的是最新版本的ConstraintLayout依赖项。

Preview section loads custom views fine as long as these views are correctly written. 预览部分可以很好地加载自定义视图 ,只要这些视图被正确编写即可。 You have to remember about all small details like draw/onDraw/dispatchDraw methods, measuring and layouting, setting correct theme, styling, providing editMode data, etc. 您必须记住所有小细节,例如draw / onDraw / dispatchDraw方法, 测量和布局,设置正确的主题,样式,提供editMode数据等。

The deal is that Android Studio has its own Context and Resources classes which are unable to perform certain things. 问题在于,Android Studio具有自己的Context和Resources类,它们无法执行某些操作。 For example these classes lack implementation of reading assets from assets folder and raw resources from raw folder. 例如,这些类缺乏从资产文件夹读取资产和从原始文件夹读取原始资源的实现。

To load a custom View, you need assets folder which you don't have access to in Android Studio. 要加载自定义视图,您需要没有Android Studio中访问权限的资产文件夹。 So make sure your custom icons file names are in lowercase and with the correct file extension. 因此,请确保您的自定义图标文件名是小写且带有正确的文件扩展名。

I have found the solution to my own problem from the answer from an online community I asked about. 我从我问过的一个在线社区的答案中找到了解决自己问题的解决方案。 Under the dependancies in the gradle build scripts, beta 1 should be used or lower. 在gradle构建脚本中的依赖关系下,应使用beta 1或更低版本。 The current version of the support library beta 2 is quite buggy. 支持库beta 2的当前版本有很多错误。 Like this: 像这样:

implementation 'com.android.support:appcompat-v7:26.0.0-beta1'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM