【问题标题】:Can't scroll in a GridView in a swipeRefreshLayout无法在 swipeRefreshLayout 的 GridView 中滚动
【发布时间】:2018-01-28 15:58:34
【问题描述】:

我遇到了 SwipeRefreshLayout 的问题。我在两个 GridView 中有一个布局,每次我在 GridView 中向上滚动时,都会触发滑动以刷新布局,并且您永远无法滚动回布局的顶部。有人有什么想法吗?

我检查了thisthis,但这不适用于 GridView。可以的话请帮忙

滑动刷新布局

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:baselineAligned="false"
    android:orientation="vertical">


    <GridView
        android:id="@+id/GridView1"
        android:layout_width="wrap_content"
        android:layout_height="31dp"
        android:numColumns="1"
        android:padding="1dp" />

    <GridView
        android:id="@+id/GridView2"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:footerDividersEnabled="false"
        android:numColumns="3"
        android:padding="1dp" />

</LinearLayout>


</android.support.v4.widget.SwipeRefreshLayout>

【问题讨论】:

    标签: java android xml gridview


    【解决方案1】:

    尝试将android:fillViewport="true" 添加到您的 SwipeRefreshLayout。

    【讨论】:

      【解决方案2】:

      将您的线性布局 id 设置为 android:id="@+id/parentPanelLL" 并在您的活动中编写以下代码...

      swipe_container.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
              @Override
              public void onScrollChanged() {
                  if (parentPanelLL.getScrollY() == 0) {
                      swipe_container.setEnabled(true);
                  } else {
                      swipe_container.setEnabled(false);
                  }
              }
          });
      

      试试这个...

      【讨论】:

      • 明天会测试这个。
      • 还有其他想法吗?
      • 你的意思是 SwipeRefreshLayout -> LinearLayout -> SwipeRefreshLayout?
      • 线性滑动然后线性
      猜你喜欢
      • 2015-01-18
      • 2016-10-24
      • 1970-01-01
      • 1970-01-01
      • 2016-08-09
      • 1970-01-01
      • 1970-01-01
      • 2021-03-07
      • 1970-01-01
      相关资源
      最近更新 更多