[英]How to make the whole page scrollable that contains a GridView?
我有一个页面,其中包含一个NavigationDrawer,imageView,两个flipperView和一个gridView。 以前只有gridView是可滚动的,所以为了使整个页面都可滚动,我将所有视图都放在了nestedScrollView中,但是现在即使gridView也无法滚动。 而且,第一个flipperView不会显示任何鳍状肢,只会显示纯蓝色背景视图。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:nestedScrollingEnabled="true"
tools:context="com.example.xxx.xxx.MainActivity"
app:layout_behavior="android.support.design.widget.AppBarLayout.ScrollingViewBehaviour">
<android.support.design.widget.NavigationView
android:id="@+id/navView"
android:layout_width="200dp"
android:layout_height="match_parent"
app:menu="@menu/navigation_menu"
android:layout_gravity="start"
app:layout_behavior="android.support.design.widget.AppBarLayout.ScrollingViewBehaviour"
android:alpha="0.4"/>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never"
android:clipToPadding="false">
<LinearLayout
android:orientation="vertical"
android:background="#0F0F0F"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
tools:context="com.example.xxxx.myapplication.MainActivity"
android:isScrollContainer="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="75dp"
android:background="#ff77"
android:layout_marginTop="5dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/banner1"
android:src="@drawable/b1"
android:scaleType="fitXY"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="75dp"
android:background="#2252FF"
android:id="@+id/rel1"
android:layout_marginTop="5dp">
<technolifestyle.com.imageslider.FlipperLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/flipper1">
</technolifestyle.com.imageslider.FlipperLayout>
</RelativeLayout>
<RelativeLayout
android:layout_marginTop="5dp"
android:id="@+id/rel2"
android:layout_width="match_parent"
android:layout_height="75dp"
android:background="#2252FF">
<technolifestyle.com.imageslider.FlipperLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/Flipper2">
</technolifestyle.com.imageslider.FlipperLayout>
</RelativeLayout>
<RelativeLayout
android:background="#fff090"
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:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0f0f0f"
android:numColumns="3"
android:padding="2dp"
android:gravity="center"
android:horizontalSpacing="2dp"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp">
</GridView>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.DrawerLayout>
ListViews具有其自己的可滚动行为。 您需要取消才能将其添加到GridView中,也可能要添加到FliperLayouts中。
android:nestedScrollingEnabled="false"
或通过代码:
gridView.setNestedScrollingEnabled(false);
希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.