Android布局:无法看到布局视图

时间:2017-07-17 05:59:17

标签: android android-studio android-studio-3.0

我刚刚安装了Android Studio 3 Preview Canary 6.由于以下错误,我无法在activity_main.xml中预览xml布局:

  1. 渲染问题
  2. 无法实例化一个或多个类
  3. 当我安装Canary 5时也会发生这种情况。我认为升级到Canary 6会解决这个问题,但事实并非如此。请帮我修复它,这样我就可以开始构建我的应用了。

    My current situation

    这是我的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>
    

3 个答案:

答案 0 :(得分:0)

您不应该在StackOverflow上发布Android Studio的Canary版本的错误。这些类型的问题和帮助你应该在android studio bugtracker中收到。

请注意,它被称为Canary版本,因为它充满了bug,谷歌知道这一点,他们甚至知道错误并明确说出他们知道的错误。

检查here to see the releases and bugs

答案 1 :(得分:0)

首先确保您使用的是最新版本的ConstraintLayout依赖项。

只要正确编写了这些视图,

预览部分就可以加载自定义视图。您必须记住所有小细节,例如 draw / onDraw / dispatchDraw 方法,测量和布局,设置正确的主题,样式,提供editMode数据等。

这笔交易是Android Studio有自己的Context和Resources类,无法执行某些操作。例如,这些类缺少从资源文件夹中读取资产和从原始文件夹中读取原始资源的实现。

要加载自定义视图,您需要在Android Studio中无法访问的资源文件夹。因此,请确保您的自定义图标文件名为小写且文件扩展名正确

答案 2 :(得分:0)

我从我询问的在线社区的答案中找到了解决我自己问题的方法。在gradle构建脚本中的依赖项下,应使用beta 1或更低版本。支持库beta 2的当前版本非常错误。像这样:

implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
相关问题