问题描述
我有:
1.Coordinator布局
2.appbar布局(协调员布局的子元素)
3.Collapsing工具栏布局(应用栏的子元素)
4.NestedScrollView (协调员的孩子)
我想在 NestedScrollView
该用户可以滚动整个屏幕空间。
我的问题是目前gridview占用 NestedScrollView ,而不是全部空间 NestedScrollView ,并在该部分内滚动,如图所示:
<?xml version =1.0encoding =utf-8? >
android:layout_width =match_parent
android:id =@ + id / app_bar
android:layout_height =wrap_content
android:theme =@ style / AppTheme.AppBarOverlay>
< android.support.design.widget.CollapsingToolbarLayout
android:id =@ + id / collapsing_toolbar
android:layout_width =match_parent
android :layout_height =196dp
android:background =#3f51b5
app:contentScrim =@ color / colorPrimary
app:expandedTitleMarginEnd =64dp
app:expandedTitleMarginStart =48dp
app:layout_scrollFlags =scroll | exitUntilCollapsed>
< ImageView
android:id =@ + id / imageview
android:layout_width =match_parent
android:layout_height = match_parent
android:scaleType =centerCrop
android:src =@ drawable / index
app:layout_collapseMode =parallax/>
< android.support.v7.widget.Toolbar
android:id =@ + id / toolbar
android:layout_width =match_parent
android :layout_height =?attr / actionBarSize
app:layout_collapseMode =pin
app:layout_scrollFlags =scroll | enterAlways
app:popupTheme =@ style / AppTheme.PopupOverlay/ >
< /android.support.design.widget.AppBarLayout>
< android.support.v4.widget.NestedScrollView
android:layout_width =match_parent
android:layout_height =match_parent
app:layout_behavior =@ string / appbar_scrolling_view_behavior >
< GridView
android:layout_width =match_parent
android:layout_height =match_parent
android:layout_marginLeft =1dp
android: layout_marginRight =1dp
android:id =@ + id / gridView
android:verticalSpacing =1dp
android:horizontalSpacing =1dp
android:numColumns =2
android:stretchMode =columnWidth/>
< /android.support.v4.widget.NestedScrollView>
< android.support.design.widget.FloatingActionButton
android:id =@ + id / fab
android:layout_width =wrap_content
android :layout_height =wrap_content
android:layout_gravity =right | bottom
android:layout_margin =@ dimen / fab_margin
android:src =@ android:drawable / ic_dialog_email/ >
GridView
已经内置了滚动功能,因此它与 NestedScrollView
冲突。您应该使用带有 GridLayoutManager
和 appbar_scrolling_view_behavior
的 RecyclerView
布局行为代替 NestedScrollView
。
I have:1.Coordinator layout2.appbar layout (child of Coordinator layout)3.Collapsing toolbar layout (child of app bar)4.NestedScrollView (child of coordinator)
I want to put a grid view inside NestedScrollView
so that user can scroll over the entire screen space.
My problem is that currently the gridview occupies a small portion of the NestedScrollView
and not full space of NestedScrollView
and scrolls inside that portion,like in this image:
As you can see my gridview height is limited upto only that highlighted portion in sky blue color, i want that to occupy the entire screen space below that image(which is my Collapsing toolbar).i tried different ways but nothing works out.my xml file is:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:id="@+id/app_bar"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="196dp"
android:background="#3f51b5"
app:contentScrim="@color/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/index"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</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"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:id="@+id/gridView"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
android:numColumns="2"
android:stretchMode="columnWidth"/>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
GridView
already has scrolling built in, so it conflicts with a NestedScrollView
. You should be using a RecyclerView
with a GridLayoutManager
and appbar_scrolling_view_behavior
layout behavior in place of the NestedScrollView
.
这篇关于gridview内部的嵌套滚动视图只能使用somepart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!