Раскладка вкладок только сваливается при броске, а не при медленной прокрутке - PullRequest
0 голосов
/ 29 мая 2018

для приведенного ниже макета, когда я прокручиваю содержимое вверх на странице в пейджере ... если я удерживаю палец на экране и медленно прокручиваю вверх, макет вкладки не сворачивается в панель инструментов, но если я переключаюсьсодержание вверх, это делает.Есть идеи, почему?

activity_home.xml

    <layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".newnav.home.HomeActivity">

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".newnav.NavigationActivity">

        <!-- Check whether do we need this surface view still? -->
        <SurfaceView
            android:id="@+id/surfaceView"
            android:layout_width="0dp"
            android:layout_height="0dp" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <com.my.package.view.MyToolBar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:background="@color/primary_color" />

            <FrameLayout
                android:id="@+id/fragment_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@id/toolbar" />

            <com.my.package.view.SomeCustomView
                android:id="@+id/breaking_news_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true" />
        </RelativeLayout>

        <com.my.package.navigation.NavigationLayout
            android:id="@+id/navigation_layout"
            android:layout_width="320dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@android:color/white"
            android:fitsSystemWindows="true" />
    </android.support.v4.widget.DrawerLayout>
</layout>

frag_home.xml (родительский макет имеет панель инструментов):

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:fitsSystemWindows="true"
            app:layout_behavior="com.nbc.news.newnav.home.NbcTabBarScrollingBehavior">

            <android.support.design.widget.TabLayout
                android:id="@+id/tabLayout"
                style="@style/HomeTabDesign"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/top_nav_tab_bg"
                app:tabBackground="@color/transparent"
                android:elevation="4dp"
                android:minHeight="@dimen/tab_layout_height"
                app:layout_scrollFlags="scroll|enterAlways"
                app:tabGravity="fill"
                app:tabIndicatorColor="@color/home_tab_strip_color"
                app:tabIndicatorHeight="3dp"
                app:tabMaxWidth="0dp"
                app:tabMode="fixed"
                app:tabSelectedTextColor="@color/home_tab_text_color_selected"
                app:tabTextColor="@color/home_tab_text_color_normal" />

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

        <com.my.package.view.MyViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </android.support.design.widget.CoordinatorLayout>
</layout>

section_fragment.xml (представление, которое прокручивается):

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.my.package.view.ProgressiveFrameLayout
        android:id="@+id/progressiveLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/divider_white"
        app:contentLayoutId="@id/contentLayout">

        <FrameLayout
            android:id="@+id/contentLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v4.widget.SwipeRefreshLayout
                android:id="@+id/swipeRefreshLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/sectionRecyclerView"
                    android:layout_width="match_parent"
                    android:descendantFocusability="blocksDescendants"
                    android:layout_height="match_parent"
                    android:background="@android:color/white" />
            </android.support.v4.widget.SwipeRefreshLayout>

            <FrameLayout
                android:id="@+id/adContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|center_horizontal" />
        </FrameLayout>

    </com.nbc.news.view.ProgressiveFrameLayout>
</layout>

1 Ответ

0 голосов
/ 12 июня 2018

Старый ответ

Это решение не сработало в данном случае.Но это может быть полезно для других.

Вы не предоставили необходимую часть своего кода.Однако я сильно подозреваю, что вы используете промежуточную раскладку между SwipeRefreshLayout и вашим Recyclerview (или ListView).Другими словами, SwipeRefreshLayout не является прямым родителем Recyclerview.Исправьте это, и это будет работать.

Если вы хотите узнать, что на самом деле происходит в фоновом режиме

Если вы проверите исходный код Android, вы можете найти метод canSwipeRefreshChildScrollUp().Ответственным является решение о возможности прокрутки вверх дочернего представления этого макета.Это необходимо переопределить, если дочернее представление является настраиваемым представлением.

public boolean canChildScrollUp() {
        if (mChildScrollUpCallback != null) {
            return mChildScrollUpCallback.canChildScrollUp(this, mTarget);
        }
        if (android.os.Build.VERSION.SDK_INT < 14) {
            if (mTarget instanceof AbsListView) {
                final AbsListView absListView = (AbsListView) mTarget;
                return absListView.getChildCount() > 0
                        && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                                .getTop() < absListView.getPaddingTop());
            } else {
                return ViewCompat.canScrollVertically(mTarget, -1) || mTarget.getScrollY() > 0;
            }
        } else {
            return ViewCompat.canScrollVertically(mTarget, -1);
        }
    }

Если вы используете промежуточное представление, макет обновления смахивания будет предполагать, что это target (см.mTarget в 6-й строке метода) и реализация по умолчанию этого представления всегда возвращает false, что приведет к этой проблеме.

Новый ответ

Дочерний объект CoordinatorLayout должен реализовать интерфейс NestedScrollingChild.попробуйте обернуть свой FrameLayout в NestedScrollView

...