NestedScrollView containing content smaller than the height of the screen. Scrolling in CoordinatorLayout

I am trying to implement ActionScript scrolling behavior with ActionBar content presented in Material Design.

I am trying to do this on a page containing SlidingTabLayoutand ViewPageras a direct affinity to AppBarLayout. I ended up in the current state by adding app:layout_behavior="@string/appbar_scrolling_view_behavior"in ViewPager.

This led to two unexpected situations:

1) When the content is Fragmentless than the height of the screen, vertical scrolling still occurs (the AppBarLayoutcontent should not scroll unless the neighbor scrolls).

2) Scrolling does not occur when a scroll touch event begins with a touch child. Edit: This problem is described here. Problem 182549

You can see on this gif that the first ScrollEvent on the page displays problem 1, and the second scroll on the page shows problem 2. (Oddly enough, problem 2 is not obvious on page 1).

enter image description here

I created a whole demo project that you can find on GitHub that shows this error: https://github.com/gwoodhouse/TestApplication

For a quick reference my Activities xml

<?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:background="@color/teal"
                                                 android:orientation="vertical">


    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:background="@color/teal"
            app:layout_scrollFlags="scroll|enterAlways"/>

        <com.example.graemecastle.testapplication.SlidingTabLayout
            android:id="@+id/slidingTabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/background"
            app:layout_scrollFlags="scroll|enterAlways"/>

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

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


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

My XML fragment looks like this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    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">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:orientation="vertical">

        <android.support.v7.widget.CardView
            android:layout_margin="16dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            app:cardBackgroundColor="@color/green"
            app:cardElevation="2dp">

            <LinearLayout

                android:layout_width="wrap_content"
                android:layout_height="?android:attr/actionBarSize"
                android:background="?android:attr/selectableItemBackground"
                android:clickable="true"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:text="Button"
                    android:textColor="#FFFFFF"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="16dp"
                    android:text=">"
                    android:textColor="#FFFFFF"/>
            </LinearLayout>
        </android.support.v7.widget.CardView>

        <!-- Extra Buttons Added Here to show how view which should scroll scroll correctly -->
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

So far, the capture has onInterceptTouchEvent()not let me know what is happening. Somebody knows?

+4

Source: https://habr.com/ru/post/1607991/


All Articles