繁体   English   中英

没有找到 app:layout_scrollflags 的资源 ID,来自 CollapsingToolbarLayout

[英]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

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

照我说的做:

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

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

尝试这个

添加应用级build.gradle

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

然后构建->重建项目

正如其他人所说,您肯定需要向您的 android 应用程序添加设计支持库依赖项。 最简单的方法是将以下内容添加到应用程序级别的 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 或后代。 如果您想将操作栏添加到您的活动,那么您的主题应该是 AppCompat。 就我而言,我使用的是android:Theme.Material因为它失败了。 将其更改为Theme.AppCompat.Light.NoActionBar对我Theme.AppCompat.Light.NoActionBar

Androidx 方案:

如果您使用的是AndroidX ,上述解决方案将不起作用

您将需要实现这一点:

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

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

文件 > 使缓存无效/重新启动

有关更多信息,请查看迁移到 AndroidX 页面

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

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

为此,您应该使用这种类型的布局层次结构。 确保设计支持库在 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>

这是我做的

  1. 从 * 导入AppCompat V7

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

并在导入项目对话框中检查复制到工作区

  1. 从 apcompat 到 Android 6.0 的目标 Android Build 版本

项目->属性->Android

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

  1. 从导入设计库

C:\\生产力\\android-sdks\\extras\\android\\support\\design

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

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

项目->属性->Android。

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

    项目->属性->Android

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

恭喜你现在可以在 Eclipse 中使用材料设计。希望它会帮助某人

添加应用级 build.gradle

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM