无法滚动在其下面具有网格视图的屏幕和listView



i具有以下XML,其下方具有GridView和Framelayout。我的要求是,如果我向上滚动屏幕,则整个屏幕应该滚动,但对我来说,listView scrolls

以下是XML文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@color/white"
android:focusableInTouchMode="true"
android:paddingBottom="@dimen/activity_vertical_margin">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/time_card_header"
    android:id="@+id/scrollView">
<GridView
     android:id="@+id/timecard_grid"
     android:layout_width="match_parent"
     android:layout_height="130dp"
     android:layout_margin="3dp"
     android:fitsSystemWindows="true"
     android:gravity="center_horizontal"
     android:horizontalSpacing="1dp"
     android:numColumns="3"
     android:stretchMode="columnWidth"
     android:verticalSpacing="1dp" />
    </ScrollView>
<FrameLayout
    android:id="@+id/timecard_reports"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="@color/white"
    android:layout_below="@+id/scrollView"/>
</RelativeLayout

实际上gridview和ListView已经滚动。无需将上述小部件放入ScrollView。首先,删除ScrollView。我认为您需要修复Framelayout,并在上面显示GridView。为此,首先在线性布局中使用align_parentbottom true在线性布局中使用framelayout。之后,请将GridView放在Framelayout上方。这将解决问题。

只需将Linearlayout放置在滚动视图之下,然后将其放置。

<scrollview>
<linearlayout >
<gridview />
</linearlayout >
</scrollview>

对不起,我从移动设备中提供了ANS,但概念是相同的。

您可以将recyclerview与gridlayoutmanager一起使用,并将recyclerview的nestedscrollingenable设置为false。而不是scrollview使用nestedscrollview作为recyclerview的父:

   private void setUpRecyclerView(View view) {
    recyclerView = view.findViewById(id.repliesList);
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setLayoutManager(new GridLayoutManager(getActivity(),numberOfColumns));
}

和XML文件:

 <android.support.v4.widget.NestedScrollView
                android:id="@+id/nestedScroll"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    <RelativeLayout 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"
        android:background="@color/white"
        android:focusableInTouchMode="true"
        android:paddingBottom="@dimen/activity_vertical_margin">
        <RecyclerView
             android:id="@+id/timecard_grid"
             android:layout_width="match_parent"
             android:layout_height="130dp"
             android:layout_margin="3dp"
             android:fitsSystemWindows="true"
             android:gravity="center_horizontal"
             android:horizontalSpacing="1dp"
             android:numColumns="3"
             android:stretchMode="columnWidth"
             android:verticalSpacing="1dp" />
        <FrameLayout
            android:id="@+id/timecard_reports"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:background="@color/white"
            android:layout_below="@+id/scrollView"/>
        </RelativeLayout
    </android.support.v4.widget.NestedScrollView>

最新更新