如何使包含GridView的整个页面可滚动?

时间:2019-02-24 10:53:28

标签: android android-layout

我有一个页面,其中包含一个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>

1 个答案:

答案 0 :(得分:0)

ListView具有其自己的可滚动行为。您需要取消才能将其添加到GridView中,也可能要取消添加到FliperLayouts中。

android:nestedScrollingEnabled="false"

或通过代码:

gridView.setNestedScrollingEnabled(false);

希望有帮助!