【问题标题】:Androidx scrolling view behavior not workingAndroidx滚动视图行为不起作用
【发布时间】:2019-04-12 10:15:02
【问题描述】:

切换到 androidx 后,以下代码停止工作。 Toolbar 下方的 TextView 用于滚动内容,但现在不滚动了。只有当我将相同的 scrollFlags 设置为 Toolbar 时,我才设法让它工作,但我想保持它在适当的位置。除了将 Toolbar 移出 AppBarLayout 和 CoordinatorLayout 之外,还有其他解决方案吗?

<androidx.coordinatorlayout.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
                app:title="Non-scrollable title"
                android:layout_width="wrap_content"
                android:layout_height="?android:attr/actionBarSize"/>

        <TextView
                app:layout_scrollFlags="scroll"
                android:layout_margin="16dp"
                android:textSize="20sp"
                android:text="this should scroll with the content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <!-- some scrollable content here -->

    </androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

【问题讨论】:

    标签: android-appbarlayout androidx


    【解决方案1】:

    替换属性 老的: app:layout_behavior="@string/appbar_scrolling_view_behavior"

    新: app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"

    并添加

    implementation 'com.google.android.material:material:1.0.0'
    

    【讨论】:

    • 这是保存在此资源中的内容&lt;string name="appbar_scrolling_view_behavior" translatable="false"&gt;com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior&lt;/string&gt; 与您所写的完全相同
    【解决方案2】:

    就我而言,问题出在 NestedScrollView 的边缘。我从 NestedScrollView 中删除了边距,一切都开始工作了。

    【讨论】:

      猜你喜欢
      • 2019-03-31
      • 2019-07-01
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多