【问题标题】:attribute layout_scrollFlags not found未找到属性 layout_scrollFlags
【发布时间】:2018-12-20 12:32:21
【问题描述】:

以下是我遇到问题的 XML 文件。我正在研究 Fragments 和 viewPager,这是我第一次参与这项工作,所以它对我来说几乎是新的,我不知道确切的错误是什么,但我是由于版本问题你说什么你有什么建议??? 找不到layout_scrollFlags(又名com.example.apex.viewpageadapter:layout_scrollFlags)

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            style="@style/MyStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed" />

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


    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

【问题讨论】:

    标签: xml android-layout android-fragments android-viewpager android-tablayout


    【解决方案1】:

    您很可能忘记在 build.gradle 脚本中添加所需的依赖项:

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

    【讨论】:

      【解决方案2】:

      你需要添加依赖:

      implementation 'androidx.coordinatorlayout:coordinatorlayout:x.x.x'
      implementation 'com.google.android.material:material:x.x.x'
      

      然后将代码添加到您的片段布局 xml 中,如下所示:

      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">
      
          <androidx.coordinatorlayout.widget.CoordinatorLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
      
              <com.google.android.material.appbar.AppBarLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">
      
                  <androidx.appcompat.widget.Toolbar
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_weight="0"
                      app:layout_scrollFlags="scroll|enterAlways" />
      
                  <android.support.design.widget.TabLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      app:layout_scrollFlags="scroll|enterAlways" />
      
              </com.google.android.material.appbar.AppBarLayout>
      
          </androidx.coordinatorlayout.widget.CoordinatorLayout>
      
      </LinearLayout>
      

      确保您已正确实现依赖项和 xml。就是这样。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-26
        • 2013-10-13
        • 2017-08-20
        • 1970-01-01
        • 1970-01-01
        • 2015-02-15
        • 2013-01-07
        • 2012-01-07
        相关资源
        最近更新 更多