【问题标题】:unable to scroll the screen which has grid view and listview below it无法滚动下面有网格视图和列表视图的屏幕
【发布时间】:2017-09-25 18:36:42
【问题描述】:

我有以下 xml,它下面有 Gridview 和 framelayout。 我的要求是如果我向上滚动屏幕整个屏幕应该滚动,但对我来说只有列表视图滚动

下面是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

【问题讨论】:

    标签: java android listview scrollview


    【解决方案1】:

    其实 GridView 和 Listview 已经滚动了。无需将上述小部件放在滚动视图中。首先,删除滚动视图。我认为您需要将 FrameLayout 固定在底部并在上方显示 gridview。首先在线性布局中使用 align_parentbottom 为 true 的 FrameLayout。之后,请将 gridview 放在 FrameLayout 上方。这将解决问题。

    【讨论】:

    • 所以如果我滚动屏幕,网格视图和框架布局会同时滚动吗?
    • 我不希望 framelayout 单独滚动。当我向上滚动时,所有屏幕都应与 gridview 一起滚动到 listview 的最后一项
    • 请查看devexchanges.info/2015/03/…。这将解决您的问题
    【解决方案2】:

    只需将线性布局放在滚动视图下方,然后放在网格视图下方。

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

    对不起,我从手机上给出答案,但概念是一样的。

    【讨论】:

      【解决方案3】:

      您可以将 RecyclerView 与 GridLayoutManager 一起使用,并将 recyclerView 的 nestedScrollingEnabled 设置为 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>
      

      【讨论】:

        猜你喜欢
        • 2012-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-11
        • 1970-01-01
        • 1970-01-01
        • 2021-10-29
        • 2017-07-31
        相关资源
        最近更新 更多