【发布时间】:2014-07-02 22:20:13
【问题描述】:
我有一个SwipeRefreshLayout 在活动中显示的片段内部使用。滑动确实会执行刷新,但在我拉下后它会立即恢复并且没有不确定进度的指示(动画进度条)。它只是消失了,但 仍然 在完成后调用 onRefresh()。这是我的布局……
活动布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ListView
android:id="@+id/left_drawer"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:dividerHeight="1px"
android:background="@color/drawer_background_gray"
android:clipToPadding="false"/>
</android.support.v4.widget.DrawerLayout>
片段布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"/>
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/empty_text_size"
android:layout_gravity="center"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textColor="@color/brand_green"/>
<ProgressBar
android:id="@android:id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateOnly="true"
android:visibility="gone"
android:layout_gravity="center"/>
</FrameLayout>
初始化Fragment布局的代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_list, null);
swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorScheme(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
return view;
}
刷新时通常会有 3 到 6 秒的延迟,这足以在查看日志时引起注意。它应该是可见的,当我使用现在已弃用的 ActionBar-PullToRefresh 库时它工作正常。我尝试将 SwipeRefreshLayout 设为 Fragment 布局的根视图,并尝试删除空文本和进度视图,但仍然无法正常工作。
在我的实际代码中还有几个步骤我无法透露,因为它是为我的公司设计的应用程序。但这只是为了为许多做类似事情的不同片段提供类似的基础,它不应该影响任何功能。
【问题讨论】:
-
请您编辑您的帖子并包含您的
SwipeRefreshLayout实现,好吗?进度条是否有足够的时间实际显示,或者您的数据刷新速度是否过快? -
@adneal 刚刚添加了更多细节和代码
-
您发布或所说的内容并没有任何明显的错误,至少据我所知。您可以尝试实现一些虚拟数据以查看问题是否仍然存在。您也可以尝试调用
SwipeRefreshLayout.setRefreshing(true),而不是下拉查看进度条是否会以这种方式显示。无论如何,这有点奇怪。如果您能想到其他任何事情,您绝对应该更新您的帖子。 -
@adneal 好吧,所有数据都从我公司的服务器中提取出来,但是我会尝试手动调用 setRefreshing(bool) 看看是否有效
-
@adneal 即使手动使用 setRefreshing(true) 也不起作用。这真的很奇怪。
标签: android xml view fragment swiperefreshlayout