android / views-widgets-samples

Multiple samples showing the best practices in views-widgets on Android.
Apache License 2.0
5.04k stars 3.01k forks source link

ViewPager2's bug #97

Open wj576038874 opened 4 years ago

wj576038874 commented 4 years ago

Viewpager2 combined with the appbar_scrolling_view_behavior of the CoordinatorLayout USES some problems, the top appbarlayout does not follow the slide

jfresen commented 4 years ago

Thanks for bringing this to our attention.

Could you tell us more about how you've used ViewPager2, Coordinator Layout and AppBarLayout together? What is the view hierarchy in which ViewPager2 resides and what is the view hierarchy of ViewPager2's current page, and what attributes are necessary to reproduce the problem?

Which versions of all AndroidX libraries did you use?

Ideally, could you provide us with a sample app that demonstrates the problem and only uses a minimal view hierarchy with which you can reproduce the problem? This will allow us to pinpoint and solve the problem.

Thanks, Jelle

wj576038874 commented 4 years ago

Thanks for bringing this to our attention.

Could you tell us more about how you've used ViewPager2, Coordinator Layout and AppBarLayout together? What is the view hierarchy in which ViewPager2 resides and what is the view hierarchy of ViewPager2's current page, and what attributes are necessary to reproduce the problem?

Which versions of all AndroidX libraries did you use?

Ideally, could you provide us with a sample app that demonstrates the problem and only uses a minimal view hierarchy with which you can reproduce the problem? This will allow us to pinpoint and solve the problem.

Thanks, Jelle

Please wait a moment, I am a little busy with my work. When I am free, I will write a demo and attach the source code to provide to you. You can see the specific problem

amardeepkumar commented 4 years ago

Dependency

implementation "androidx.viewpager2:viewpager2:1.0.0"

Activity

val TAB_ICON = listOf<Int>(R.drawable.ic_event, R.drawable.ic_forum, R.drawable.ic_headset)
class ScrollsWithTabActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_app_bar_scroll_with_tabs)

    setSupportActionBar(toolbar)
    findViewById<Toolbar>(R.id.toolbar).title = title

    val pagerAdapter = ScreenSlidePagerAdapter(this)
    viewpager.adapter = pagerAdapter

    TabLayoutMediator(tab_layout, viewpager) { tab, position ->
        tab.icon = getDrawable(TAB_ICON[position])
        }.attach()
    }
}

Layout

<?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:id="@+id/activity_main"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"
  tools:context=".ui.silkscreen.AppBarFlexOverlappingActivity">

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.google.android.material.appbar.MaterialToolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_marginStart="-12dp"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>

<androidx.viewpager2.widget.ViewPager2
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

It should ideally hide toolbar while scrolling down, but toolbar always stick on top

hvar90 commented 3 years ago

i have the same problem, i am using this java version of NestedScrollableHost https://gist.github.com/KhaledAlharthi/e7e52cdf689295abb76b9437e1e02228

and SwipeRefreshLayout is not working well too

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/swiperefresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        <schan.main.common.NestedScrollableHost
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp">
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recyclerview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
        </schan.main.common.NestedScrollableHost>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>