【发布时间】:2016-10-29 20:18:13
【问题描述】:
我正在尝试在我的选项卡式视图上应用 SwipeRefrshLayout。
这是我想要 swipeRefreshLayout 的选项卡片段的布局文件
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:divider="@null" />
</ScrollView>
这是activity的布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/action_bar"
style="@style/Widget.MaterialSheetFab.ToolBar" />
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
style="@style/Widget.MaterialSheetFab.TabLayout" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_below="@+id/appbar"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</RelativeLayout>
片段文件中的代码:
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (SuperAwesomeCardFragment.listAchievements.getChildAt(0) != null) {
StudentInfoMainActivity.swipeRefreshLayout.setEnabled(listAchievements.getFirstVisiblePosition() == 0 && listAchievements.getChildAt(0).getTop() == 0);
}
}
在应用上述布局和 google 示例代码中显示的代码示例后,我成功地实现了 swiperefreshllayout。但是存在无法向下滚动的问题,因为滑动覆盖了它。根据堆栈溢出线程https://stackoverflow.com/a/35779571/4180170,我添加了解决我的问题的代码。但这又增加了一个问题。 列表的第一行的高度大于我的屏幕尺寸的情况,然后列表仅显示第一个元素。其他元素不显示在屏幕上。仅当行中的第一个元素较大时才会发生这种情况。如果我添加另一行高度小于或等于屏幕大小,则所有元素都将正确显示。
我想强调的另一点是,如果我在活动中使用类似的代码(而不是选项卡或片段),它会按预期完美运行,并且不会遇到以下问题。 这有点奇怪。
我添加了两张图片: Image1:在此图中,列表视图中的第一个元素的高度小于屏幕高度,因此列表视图中的所有元素在上下滚动时都可见。
Image2:这里我刚刚从图像 1 中删除了列表视图的第一个元素。所以看到的照片是现在列表视图中的第一个元素。在这种情况下,如图所示,元素的高度(Image+padding 和所有)大于屏幕尺寸(高度)。现在,当我尝试向下滚动时,滚动只会持续到图像已满。在向下滚动时,我无法看到列表视图中的任何其他行。
更新: 在 Logcat 中多次获取以下行
10-30 08:56:02.851 19665-19665/com.malav.holistree E/SwipeRefreshLayout: Got ACTION_MOVE event but don't have an active pointer id.
【问题讨论】:
-
您能否发布屏幕截图并详细说明您的问题?我无法正确理解您的问题。
-
我添加了屏幕截图和一些与屏幕截图相关的更多解释
-
很好,现在问题更清楚了。问题:为什么在 ScrollView 中需要 ListView?另外,我建议您从 ListView 更改为 RecyclerView,RecyclerView 处理多个滚动视图比 ListView 更好。
标签: android listview android-fragments swiperefreshlayout