【发布时间】:2013-11-20 19:29:56
【问题描述】:
我正在尝试使用 Chris Banes 的库 Actionbar-PullToRefresh。可以找到here。
我在我的应用中使用 Tabs + ViewPager + Fragments。
我面临的问题是我的片段有一个GridView,我不知道如何使用这个库来处理它。
我通读了示例代码。他说您所要做的就是将可刷新的视图包装在 PullToRefreshLayout 中,如下所示:
<uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ptr_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Your content, here we're using a ScrollView -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ScrollView>
</uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout>
这适用于ListView、ScrollView、GridView 等内容。但是,显然这不适用于片段(标签和视图页面)。现在,在示例代码中,他用ScrollView INSTEAD 或PullToRefreshLayout 包装了可刷新片段。
我不能这样做,因为我的 Fragment 1(在标签 1 下)有一个 GridView。现在我无法将GridView 添加到ScrollView,因为这没有任何意义。
例如,如果我将GridView 放入ScrollView 中,如下所示,那就没有意义了:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ptr_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbarStyle="outsideInset" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFF000" >
<!-- MY GRID VIEW -->
<GridView
...
/>
</RelativeLayout>
</ScrollView>
上面的代码有效。有点。 (我需要禁用我的 GridView 的滚动并使用 ExpandableGridView 使其正常工作......这似乎有点矫枉过正,我什至不确定这是否会工作)。
如果我将 ScrollView 包装器替换为 PullToRefreshLayout 或任何其他布局,刷新不起作用。
怎么办?如何让我的布局与这个库一起工作而不用 ScrollView 围绕它?
我希望我已经足够清楚了。如果您需要更多信息,请告诉我。我尽力解释它。
谢谢!
【问题讨论】:
标签: android android-layout gridview android-fragments pull-to-refresh