简体   繁体   English

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

[英]no resource id found for app:layout_scrollflags from CollapsingToolbarLayout

The title of this question basically says it all.这个问题的标题基本上说明了一切。 I get the error: no resource identifier found for app:layout_scrollflags from CollapsingToolbarLayout.我收到错误:没有为来自 CollapsingToolbarLayout 的 app:layout_scrollflags 找到资源标识符。 I use eclipse and imported the design library jar file.我使用eclipse并导入了设计库jar文件。 I'm able to use the design support layouts in my classes so that's correct我可以在我的课程中使用设计支持布局,所以这是正确的

this is a piece of the code i use:这是我使用的一段代码:

<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>

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

only importing the design library jar file is not enough.仅导入设计库 jar 文件是不够的。 You need to import resource of android-design-library project while the jar file only contains class files.您需要导入android-design-library项目的资源,而jar 文件仅包含类文件。

Do as I say:照我说的做:

  1. import android-design-library project.导入android-design-library项目。 The project is at " sdk/extras/android/support/design/ ".该项目位于“ sdk/extras/android/support/design/ ”。 And set it as a library project if it is not.如果不是,则将其设置为库项目。
  2. import the above project into your main project as a library.将上述项目作为库导入到您的主项目中。

You have to do this, because xmlns:app="http://schemas.android.com/apk/res-auto" means your need local resources from your library project or the current project, in this case, it means you need resources from the library project of android-design-library .你必须这样做,因为xmlns:app="http://schemas.android.com/apk/res-auto"意味着你需要来自你的库项目或当前项目的本地资源,在这种情况下,这意味着你需要来自android-design-library库项目的资源。

try this尝试这个

add app level build.gradle添加应用级build.gradle

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

then Build -> Rebuild Project然后构建->重建项目

As others have stated you definitely need to add Design Support Library dependency to your android app.正如其他人所说,您肯定需要向您的 android 应用程序添加设计支持库依赖项。 Simplest way is to add following to app level gradle file -最简单的方法是将以下内容添加到应用程序级别的 gradle 文件中 -

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

However couple of points to note-不过有几点需要注意——

  1. This support library should not use a different version than the compileSdkVersion.此支持库不应使用与 compileSdkVersion 不同的版本。 Since I was using compileSdkVersion 25 I had to use compile 'com.android.support:design:25.3.1' and not compile 'com.android.support:design:24.2.1'由于我使用的是compileSdkVersion 25我不得不使用compile 'com.android.support:design:25.3.1'而不是compile 'com.android.support:design:24.2.1'
  2. Using the design library requires using theme.appcompat or a descendant.使用设计库需要使用 theme.appcompat 或后代。 If you want add actionbar to your activity then your theme should be AppCompat.如果您想将操作栏添加到您的活动,那么您的主题应该是 AppCompat。 In my case I was using android:Theme.Material due to which it was failing.就我而言,我使用的是android:Theme.Material因为它失败了。 Changing it to Theme.AppCompat.Light.NoActionBar worked for me.将其更改为Theme.AppCompat.Light.NoActionBar对我Theme.AppCompat.Light.NoActionBar

Androidx soution: Androidx 方案:

If you are using AndroidX the above solutions won't work .如果您使用的是AndroidX ,上述解决方案将不起作用

You will need to implement this:您将需要实现这一点:

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

Notice that Maybe you will need to Invalidate Caches/Restart for this to work for you:请注意,也许您需要使Invalidate Caches/Restart才能为您工作:

File > Invalidate Caches/Restart文件 > 使缓存无效/重新启动

For more info check the Migrating to AndroidX page .有关更多信息,请查看迁移到 AndroidX 页面

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

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

For this you should use this type of hierarchy of layouts.为此,您应该使用这种类型的布局层次结构。 Make sure the design support library is included as a reference project in the case of eclipse确保设计支持库在 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>

Here is how I did这是我做的

  1. Import AppCompat V7 from *从 * 导入AppCompat V7

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

and Check copy into workspace in import project dialog box.并在导入项目对话框中检查复制到工作区

  1. Target Android Build version of apcompat to Android 6.0 from从 apcompat 到 Android 6.0 的目标 Android Build 版本

Project->Properties->Android项目->属性->Android

it should remove all compilation error.它应该删除所有编译错误。

  1. Import Design Lib from从导入设计库

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

follow same steps to import project mentioned in 1 & 2.按照相同的步骤导入 1 和 2 中提到的项目。

  1. Mark imported design lib as Android lib and if it show error Add AppCompat V7 lib into Build path of your design lib from将导入的设计库标记为 Android 库,如果显示错误,则将 AppCompat V7 库添加到设计库的构建路径中

Project->Properties->Android.项目->属性->Android。

  1. Finally add design and appcompat to build path of Your Android project最后添加 design 和 appcompat 来构建你的 Android 项目的路径

    Project->Properties->Android项目->属性->Android

clean and build your project with Android 6.0 all compilation errors must be gone by now.使用 Android 6.0 清理并构建您的项目,所有编译错误现在都必须消失。

Congrats now you can use material design in Eclipse.Hope it will help somebody恭喜你现在可以在 Eclipse 中使用材料设计。希望它会帮助某人

Add an app level build.gradle添加应用级 build.gradle

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

the version should match to your compileSdkVersion.版本应与您的 compileSdkVersion 匹配。 I used version 28.我用的是28版。

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

相关问题 在CollapsingToolbarLayout中以编程方式更改layout_scrollFlags - Change layout_scrollFlags programmatically in CollapsingToolbarLayout BottomAppBar和FloatingActionButton app:layout_scrollFlags行为 - BottomAppBar And FloatingActionButton app:layout_scrollFlags behavior app:layout_scrollFlags =“scroll | enterAlways”不适用于LinearLayout - app:layout_scrollFlags=“scroll|enterAlways” doesn't works with LinearLayout 如何以编程方式为工具栏设置 app:layout_scrollFlags - How to set app:layout_scrollFlags for Toolbar programmatically Material design layout_scrollFlags 含义 - Material design layout_scrollFlags meanings 即使在提供“app:layout_scrollFlags”标志后,工具栏也不会滚动 - Toolbar is not scrolling off even after providing “app:layout_scrollFlags” flag Android Material Design AppBarLayout的属性layout_scrollFlags有问题 - Android Material Design AppBarLayout's attribute layout_scrollFlags problematic 设置layout_scrollFlags时,Android工具栏不会隐藏 - Android toolbar doesn't hide when set layout_scrollFlags 即使我使用layout_scrollFlags滚动收费栏,也可以在底部制作BottomNavigationView - make BottomNavigationView in bottom even if i use layout_scrollFlags to scroll Tollbar 除非工具栏具有layout_scrollflags:scroll,否则CoordinatorLayout滚动将无法正常工作 - CoordinatorLayout scroll doesn't work unless Toolbar has layout_scrollflags:scroll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM