未从 CollapsingToolbarLayout 找到 app:layout_scrollflags 的资源 ID

no resource id found for app:layout_scrollflags from CollapsingToolbarLayout

这个问题的标题基本上已经说明了一切。我收到错误: 从 CollapsingToolbarLayout 中找不到 app:layout_scrollflags 的资源标识符。我使用 eclipse 并导入了设计库 jar 文件。我可以在我的 类 中使用设计支持布局,所以这是正确的

这是我使用的一段代码:

<LinearLayout 
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"
android:orientation="vertical"
android:background="@color/activityBg"
tools:context=".MainActivity"
>

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <include
            layout="@layout/toolbar"/>

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

示例:http://android-developers.blogspot.in/2015/05/android-design-support-library.html

为此,您应该使用这种类型的布局层次结构。 确保在 eclipse

的情况下将设计支持库作为参考项目包含在内
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true" >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbarlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true" >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp" >

            <ImageView
                android:id="@+id/ivProfileImage"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                app:layout_collapseMode="parallax"
                android:contentDescription="@null"
                android:fitsSystemWindows="true"
                android:minHeight="100dp"
                android:scaleType="fitXY" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:layout_gravity="fill_vertical"
        app:layout_anchorGravity="top|start"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >
    </android.support.v4.widget.NestedScrollView>

仅导入设计库jar 文件是不够的。您需要导入 android-design-library 项目的资源,而 jar 文件仅包含 class 个文件。

照我说的做:

  1. 导入android-design-library项目。该项目位于 “sdk/extras/android/support/design/”。并将其设置为库 如果不是项目。
  2. 将上述项目作为库导入到您的主项目中。

你必须这样做,因为 xmlns:app="http://schemas.android.com/apk/res-auto" 意味着你需要从你的库项目或当前项目中获取本地资源,在这种情况下,这意味着你需要从 的库项目中获取资源android-设计库.

这是我的做法

  1. 从 *
  2. 导入 AppCompat V7

C:\Productivity\android-sdks\extras\android\support\v7\appcompat

在导入项目对话框中选中复制到工作区

  1. 目标 Android 将 apcompat 的构建版本从
  2. 升级到 Android 6.0

Project->Properties->Android

它应该消除所有编译错误。

  1. 导入 设计库

C:\Productivity\android-sdks\extras\android\support\design

按照相同的步骤导入 1 和 2 中提到的项目。

  1. 将导入的设计库标记为 Android 库,如果它显示错误,请将 AppCompat V7 库从
  2. 添加到设计库的构建路径中

Project->Properties->Android.

  1. 最后添加 design 和 appcompat 以构建您的 Android 项目的路径

    项目->属性->Android

使用 Android 6.0 清理并构建您的项目,现在所有编译错误都必须消失。

恭喜你现在可以在 Eclipse.Hope 中使用 material 设计了,它会对某人有所帮助

试试这个

添加应用级别build.gradle

    compile 'com.android.support:design:24.2.1'

然后 构建 -> 重建项目

正如其他人所说,您肯定需要向 android 应用程序添加 Design Support Library 依赖项。最简单的方法是将以下内容添加到应用级别 gradle 文件 -

compile 'com.android.support:design:25.3.1'

不过有几点需要注意-

  1. 此支持库不应使用与 compileSdkVersion 不同的版本。由于我使用的是 compileSdkVersion 25 我不得不使用 compile 'com.android.support:design:25.3.1' 而不是 compile 'com.android.support:design:24.2.1'
  2. 使用设计库需要使用 theme.appcompat 或后代。如果您想将操作栏添加到 activity,那么您的主题应该是 AppCompat。在我的例子中,我使用的是 android:Theme.Material,因为它失败了。将其更改为 Theme.AppCompat.Light.NoActionBar 对我有用。

尝试将此代码添加到 xml 文件:

app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"

添加应用级别build.gradle

implementation 'com.android.support:design:28.0.0'

版本应与您的 compileSdkVersion 匹配。我用的是28版。

Androidx 解决方案:

如果您正在使用 AndroidX 上述解决方案 将不起作用

您将需要执行此操作:

implementation 'com.google.android.material:material:1.1.0-alpha06'

请注意,也许您需要 Invalidate Caches/Restart 才能为您工作:

File > Invalidate Caches/Restart

有关详细信息,请查看 Migrating to AndroidX page