4

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

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

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

在此处输入图像描述

这是我的 xml 代码片段:

<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" />...

我怎样才能解决这个问题?

4

1 回答 1

-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'
于 2016-06-07T06:17:08.753 回答