gpt4 book ai didi

java - 无法使用 CollapsedToolBarLayout 中的 NestedScrollView 在 ViewPager 中完全向下滚动

转载 作者:行者123 更新时间:2023-11-29 19:12:29 30 4
gpt4 key购买 nike

我正在使用 ViewPager 创建一个带有折叠工具栏布局的 fragment 。这是布局的 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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/htab_maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.AppActivity">

<android.support.design.widget.AppBarLayout
android:id="@+id/htab_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:backgroundTint="@color/completeWhite">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/htab_collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="420dp"
android:fitsSystemWindows="true"
app:contentScrim="@color/completeWhite"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false">

<RelativeLayout
android:id="@+id/brand_page"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="parallax"
android:paddingTop="24dp"
android:layout_marginTop="?attr/actionBarSize">

//Lots of images and texts that are collapsed

</RelativeLayout>

<android.support.v7.widget.Toolbar
android:id="@+id/htab_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
android:layout_marginBottom="75dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

<android.support.design.widget.TabLayout
android:id="@+id/htab_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:tabIndicatorColor="@android:color/white"
app:tabSelectedTextColor="@color/lightGreen"
app:tabTextColor="@color/grey"/>

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

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

<io.brandie.brandie.custom.NoSwipeViewPager
android:id="@+id/htab_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_marginBottom="@dimen/spacing_giant"
android:background="@color/white"/>

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

viewPager 充满了使用 gridview 显示不同卡片的 fragment ,这是第一个选项卡的 fragment 的 xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:id="@+id/NestedScroll"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:layout_gravity="fill_vertical"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/all_campaigns_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.brandie.brandie.fragments.AllCampaignsFragment">

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/all_campaigns_grid"
android:descendantFocusability="blocksDescendants"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="2"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center" />

</FrameLayout>

</android.support.v4.widget.NestedScrollView>

有了它,我可以向下滚动屏幕上的任何位置,使工具栏折叠并展开 View 寻呼机。问题是,当工具栏完全折叠并且只显示选项卡时,我无法再滚动 viewPager。由于它包含一个包含很多项目的 gridView,这导致我无法滚动浏览所有项目,因为滚动只是“停止”。

我希望它看起来像 this

但是,当工具栏折叠时,我无法再向下滚动 viewPager。但是,我可以向上滚动它以再次显示工具栏,这没有问题。我使用的是 Android API 16,这是个问题吗?

如何解决这个非常恼人的问题?

编辑:如果我从 fragment XML 中删除 NestedScrollView,折叠的工具栏只会在我在工具栏上滚动时折叠。如果我滚动 ViewPager,我可以正确滚动浏览所有内容,但工具栏不会折叠。

最佳答案

回答您的编辑:尝试在您的 GridView 上使用 setNestedScrollingEnabled(false)

关于java - 无法使用 CollapsedToolBarLayout 中的 NestedScrollView 在 ViewPager 中完全向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44818569/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com