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