RecyclerView渲染问题

时间:2017-07-14 07:36:29

标签: android android-layout android-recyclerview

我想实现回收站视图布局,但我收到错误“渲染问题”。我尝试添加 include ,但错误仍然存​​在。我该如何解决这个问题?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/viewBg"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.waadalkatheri.popularmovies.MainActivity"
    tools:showIn="@layout/activity_main"
    android:layout_marginTop="@dimen/activity_vertical_margin">
    <include layout="@layout/activity_main"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:scrollbars="vertical" />

</RelativeLayout>

映像错误 enter image description here

错误: 我

nformation:Gradle tasks [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:compileDebugSources, :app:compileDebugAndroidTestSources, :app:compileDebugUnitTestSources]
/Users/mac/AndroidStudioProjects/popularMovies/app/src/main/res/layout/content_main.xml
Error:(2) No resource identifier found for attribute 'layout_behavior' in package 'com.example.waadalkatheri.popularmovies'
Error:(8, 26) No resource found that matches the given name (at 'layout_behavior' with value '@string/appbar_scrolling_view_behavior').
/Users/mac/AndroidStudioProjects/popularMovies/app/build/intermediates/res/merged/debug/layout/content_main.xml
Error:(2) No resource identifier found for attribute 'layout_behavior' in package 'com.example.waadalkatheri.popularmovies'
Error:(8, 26) No resource found that matches the given name (at 'layout_behavior' with value '@string/appbar_scrolling_view_behavior').
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

6 个答案:

答案 0 :(得分:1)

从代码中删除此android:scrollbars="vertical"并尝试重建项目

答案 1 :(得分:1)

首先,由于您没有使用 CoordinatorLayout ,因此您可以安全地删除有问题的app:layout_behavior="@string/appbar_scrolling_view_behavior"。在此处阅读更多相关信息:No resource identifier found for attribute 'layout_behavior' in package

然后,我认为您的 android:showIn xml属性是多余的。摆脱它。您递归地引用相同的活动(使用包含 showIn),这会弄乱您的渲染。

答案 2 :(得分:0)

使用关键字搜索所有项目:&#34; layout_behavior&#34;并删除它们的所有行。特别是在&#34; content_main.xml&#34;

答案 3 :(得分:0)

好吧我觉得我找到了你的问题。

只需更改xml中的这一行:

tools:showIn="@layout/activity_main"  to tools:showIn="@layout/activity_main.xml"

希望它有所帮助!!!

答案 4 :(得分:0)

将此添加到您应用的build.gradle

dependencies{

         compile fileTree(include: ['*.jar'], dir: 'libs')

         compile 'com.android.support:recyclerview-v7:your_version'


       }

答案 5 :(得分:0)

试试这个

只需从RelativeLayout

中删除tools:showIn="@layout/activity_main"即可

您可以在渲染错误警告!!!

下找到渲染问题的解决方案