【问题标题】:Rendering Problems Exception raised during rendering: Could not find layout resource渲染过程中引发异常:找不到布局资源
【发布时间】:2016-09-27 06:40:11
【问题描述】:

我在 Android Studio 2.2 中创建项目时遇到问题

在尝试创建 xml 布局时,出现以下错误:

渲染问题 渲染过程中引发异常:找不到布局资源

这是我的 xml 代码 sn-p :

<ScrollView xmlns:android="schemas.android.com/apk/res/android"
     xmlns:app="schemas.android.com/apk/res-auto"
     xmlns:tools="schemas.android.com/tools"
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <RelativeLayout android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
       <LinearLayout android:layout_width="match_parent" 
          android:layout_height="match_parent"                                     android:orientation="vertical"> 
        <include layout="@layout/app_bar" />...

我该如何解决这个问题?

【问题讨论】:

  • 你试过刷新吗?什么是布局资源?你想在里面包含布局吗?
  • 尝试刷新但不起作用。应用栏是布局资源。是的。
  • 如果您忽略此错误并运行您的应用程序会发生什么?运行良好吗?
  • 是的。它运行良好。
  • 那么最好忽略此类错误,代码在设计时未编译,因此此类错误会显示在预览窗格中。

标签: android android-layout android-studio android-studio-2.2


【解决方案1】:

Android Studio 2.2 为嵌套布局启动了 ConstraintLayout。添加 ConstraintLayout 作为 app_bar.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"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

</android.support.constraint.ConstraintLayout>

注意:- 不要忘记为 ConstraintLayout 添加依赖项。

compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha2'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多