材料中怪异的AppBarLayout和swiperrefreshlayout行为



我正在创建一个应用程序,具有滑动刷新功能与材质3(材质你)的设计。但是当在swiperrefreshlayout下滚动内容时,应用程序栏不会像预期的那样正常抬起。当SwipeRefreshLayout刷新时,它可以正常工作。

activity-main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:liftOnScroll="true">
<com.google.android.material.appbar.MaterialToolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="App Bar and Swipe Layout"
app:titleCentered="true"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Long lorem ipsum text..."/>
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

MainActivity.java

package com.fourbits.appbarandswiperefresh;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

我试图改变我的SwipeRefreshLayout android依赖版本从1.2.0-alpha01到1.1.0,但问题仍然存在。

我希望当内容在swiperrefreshlayout下滚动时,应用程序栏将正确抬起。

使用app:liftOnScrollTargetViewId="@id/nestedScroll"在应用程序栏布局解决了这个问题。

参考:https://github.com/material-components/material-components-android/issues/2825

相关内容

  • 没有找到相关文章

最新更新