如何修复折叠工具栏滚动问题

问题描述 投票:1回答:3

我正在尝试实现我实现的折叠工具栏,但我没有得到正确的输出。

当我尝试使用recyclerview项目进行滚动时,它不能正确滚动但是如果我在convertlerview外面滚动触摸它会滚动好

我得到这个output

<?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.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/ctolbar"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/colorPrimary"
            app:collapsedTitleTextAppearance="@style/collapsed"
            app:expandedTitleMargin="5dp"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleTextAppearance="@style/CollapsingToolbarLayoutExpandedTextStyle"
            app:layout_scrollFlags="enterAlways|enterAlwaysCollapsed|scroll"
            app:title="Profile">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/cover"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/gradient_cover" />
            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollbars="none"
        app:behavior_overlapTop="100dp"
        app:layout_anchor="@id/appbar"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <FrameLayout
                android:id="@+id/flmiddle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="30dp"
                android:paddingRight="30dp">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="35dp"
                    android:background="@drawable/background_round">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="40dp"
                        android:gravity="center_horizontal"
                        android:orientation="vertical"
                        android:paddingLeft="16dp"
                        android:paddingRight="16dp">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="16dp"
                            android:layout_marginBottom="5dp"
                            android:fontFamily="@font/righteous_regular"
                            android:gravity="center"
                            android:text="Jack Sparrow"
                            android:textColor="#ff3f4751"
                            android:textSize="25sp"
                            android:textStyle="bold" />

                        <TextView
                            android:id="@+id/tvaddress"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:layout_marginBottom="16dp"
                            android:gravity="center"
                            android:fontFamily="@font/roboto_regular"
                            android:text="221 B Baker Street, London"
                            android:textSize="15sp" />

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="16dp"
                            android:layout_marginBottom="16dp"
                            android:orientation="horizontal"
                            android:weightSum="3">

                            <LinearLayout
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:gravity="center_horizontal"
                                android:orientation="vertical">

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="Purchased"
                                    android:fontFamily="@font/josefinsans_semibold"
                                    android:textAllCaps="true"
                                    android:textColor="#ff878b91"
                                    android:textSize="10sp" />

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:fontFamily="sans-serif-condensed"
                                    android:text="1.5 K"
                                    android:textColor="#ff3f4751"
                                    android:textSize="24sp"
                                    android:textStyle="normal" />
                            </LinearLayout>

                            <LinearLayout
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:gravity="center_horizontal"
                                android:orientation="vertical">

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="Wished"
                                    android:textAllCaps="true"
                                    android:fontFamily="@font/josefinsans_semibold"
                                    android:textColor="#ff878b91"
                                    android:textSize="10sp" />

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:fontFamily="sans-serif-condensed"
                                    android:text="1.1 K"
                                    android:textColor="#ff3f4751"
                                    android:textSize="24sp" />
                            </LinearLayout>

                            <LinearLayout
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:gravity="center_horizontal"
                                android:orientation="vertical">

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="Likes"
                                    android:textAllCaps="true"
                                    android:fontFamily="@font/josefinsans_semibold"
                                    android:textColor="#ff878b91"
                                    android:textSize="10sp" />

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:fontFamily="sans-serif-condensed"
                                    android:text="450"
                                    android:textColor="#ff3f4751"
                                    android:textSize="24sp" />
                            </LinearLayout>
                        </LinearLayout>
                    </LinearLayout>
                </FrameLayout>

                <ImageView
                    android:id="@+id/imgprofile"
                    android:layout_width="68dp"
                    android:layout_height="68dp"
                    android:layout_gravity="center|top" />
            </FrameLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="20dp"
                android:layout_marginRight="16dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:fontFamily="@font/righteous_regular"
                    android:text="Collection"
                    android:textColor="#ff3f4751"
                    android:textSize="20sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="sans-serif"
                    android:text="More"
                    android:textColor="#ff3f4751"
                    android:textSize="15sp" />
            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/RecyclerViewCollection"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:clipToPadding="false"
                android:orientation="horizontal"
                android:paddingLeft="16dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="30dp"
                android:layout_marginRight="16dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:fontFamily="@font/righteous_regular"
                    android:text="Tags"
                    android:textColor="#ff3f4751"
                    android:textSize="20sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="sans-serif"
                    android:text="More"
                    android:textColor="#ff3f4751"
                    android:textSize="15sp" />
            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/RecyclerViewTags"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:clipToPadding="false"
                android:paddingLeft="16dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="30dp"
                android:layout_marginRight="16dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:fontFamily="@font/righteous_regular"
                    android:text="Offers!!!"
                    android:textColor="#ff3f4751"
                    android:textSize="20sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="sans-serif"
                    android:text="More"
                    android:textColor="#ff3f4751"
                    android:textSize="15sp" />
            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/RecyclerViewOffers"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:clipToPadding="false"
                android:orientation="horizontal"
                android:paddingLeft="16dp" />
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

任何帮助将受到高度赞赏

android scrollview android-collapsingtoolbarlayout appbar
3个回答
1
投票

您可以在使用RecyclerView时禁用NestedScrollView的嵌套滚动

recyclerView.isNestedScrollingEnabled = false

或支持旧版本;

ViewCompat.setNestedScrollingEnabled(this, shouldScroll)

1
投票

试着说:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

在RecyclerView属性中。


1
投票

你应该尝试CollapsingToolbarLayout

app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"

并为Toolbar

app:layout_scrollFlags="scroll|exitUntilCollapsed"

也尝试跟随this,当然它会帮助你很多。

© www.soinside.com 2019 - 2024. All rights reserved.