无法滚动嵌套在nestedscrollview中的gridview [英] unable to scroll gridview embeded in nestedscrollview
问题描述
我的gridview不滚动.我在gridview中有10个项目,但仅显示6个项目,并且某些项目位于底部的截止处.
my gridview does not scroll. i have 10 items in the gridview but only 6 show and some of the items at the bottom at cut off.
这是gridview的布局:
Here is the layout of the gridview:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:id="@+id/appbar_layout"
android:layout_height="@dimen/app_bar_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="@dimen/expanded_toolbar_title_margin_start"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/yelp"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:id="@+id/nestedscrollview"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:id="@+id/gridContainerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<GridView
android:id="@+id/grid"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:columnWidth="100dp"
android:gravity="center"
android:listSelector="#00000000"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
/>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
,这是该问题的两张照片.当我向上滚动时,它将yelp图像向上推,但不会在gridview上进行嵌套滚动,为什么?
and here are two photos of the issue. when i scroll upwards it pushes the yelp image up but it wont do the nested scrolling on the gridview, why ?
更新:我也尝试这样做:
UPDATE: i also tried doing this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mGridView.setNestedScrollingEnabled(true);
}
并且开始使用API棒棒糖.但我也需要它在较旧的设备上运行.为什么它不能在棒棒糖之前在设备上滚动?
AND IT STARTED WORKING ON API lollipop. But i need it to run on older devices also. why wont it scroll on devices before lollipop ?
推荐答案
您可以将RecyclerView与GridLayout一起使用,而不是GridView.然后,可以在棒棒糖之前的版本中禁用嵌套滚动.
You can use RecyclerView with GridLayout instead of GridView. Then disabling nested scrolling, can be done on pre lollipop version.
这篇关于无法滚动嵌套在nestedscrollview中的gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!