Android 如何在SwipeRefreshLayout中设置自定义刷新视图?
我必须用自定义视图更改默认刷新视图。有人能告诉我怎么做吗 任何帮助都将不胜感激。给您: 步骤1:渐变依赖性 编译'com.reginald.swiperefresh:library:1.1.1' 步骤2:xml配置Android 如何在SwipeRefreshLayout中设置自定义刷新视图?,android,swiperefreshlayout,Android,Swiperefreshlayout,我必须用自定义视图更改默认刷新视图。有人能告诉我怎么做吗 任何帮助都将不胜感激。给您: 步骤1:渐变依赖性 编译'com.reginald.swiperefresh:library:1.1.1' 步骤2:xml配置 <com.reginald.swiperefresh.CustomSwipeRefreshLayout xmlns:swiperefresh="http://schemas.android.com/apk/res-auto" android:id="@+id/s
<com.reginald.swiperefresh.CustomSwipeRefreshLayout
xmlns:swiperefresh="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
swiperefresh:refresh_mode="pull_mode"
swiperefresh:keep_refresh_head="true"
swiperefresh:enable_top_progress_bar="true"
swiperefresh:time_out_refresh_complete="2000"
swiperefresh:time_out_return_to_top="1000"
swiperefresh:return_to_top_duration="500"
swiperefresh:return_to_header_duration="500"
swiperefresh:top_progress_bar_color_1="@color/common_red"
swiperefresh:top_progress_bar_color_2="#ee5522"
swiperefresh:top_progress_bar_color_3="#ffa600"
swiperefresh:top_progress_bar_color_4="@color/common_yellow">
<!-- Attention: you can add ONLY one view in CustomSwipeRefreshLayout either in xml or java code -->
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:id="@+id/listview">
</ListView>
</com.reginald.swiperefresh.CustomSwipeRefreshLayout>
步骤4:处理刷新事件
CustomSwipeRefreshLayout mSwipeRefreshLayout;
//set onRefresh listener
mSwipeRefreshLayout.setOnRefreshListener(new CustomSwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// do something here when it starts to refresh
// e.g. to request data from server
}
});
//set RefreshCheckHandler (OPTIONAL)
mCustomSwipeRefreshLayout.setRefreshCheckHandler(new CustomSwipeRefreshLayout.RefreshCheckHandler() {
@Override
public boolean canRefresh() {
// return false when you don't want to trigger refresh
// e.g. return false when network is disabled.
}
});
// to tell the CustomSwipeRefreshLayout when your refreshing process is complete
// e.g. when received data from server
mSwipeRefreshLayout.refreshComplete();
// to handle scrolling up event
mCustomSwipeRefreshLayout.setScrollUpHandler(new CustomSwipeRefreshLayout.ScrollUpHandler() {
@Override
public boolean canScrollUp(View view) {
// e.g. check whether the scroll up event can be consumed by the RecyclerView
if (view == mRecyclerView){
return ((GridLayoutManager)mLayoutManager).findFirstCompletelyVisibleItemPosition() != 0;
}
return false;
}
});
// to handle scrolling left of right event
mCustomSwipeRefreshLayout.setScrollLeftOrRightHandler(new CustomSwipeRefreshLayout.ScrollLeftOrRightHandler() {
@Override
public boolean canScrollLeftOrRight(View view, int direction) {
// e.g. check whether the scroll left or right event can be consumed by your Custom View
if (view == myCustomView){
return myCustomView.canScrollHorizontal(direction);
}
return false;
}
});
步骤5:处理滚动事件
CustomSwipeRefreshLayout mSwipeRefreshLayout;
//set onRefresh listener
mSwipeRefreshLayout.setOnRefreshListener(new CustomSwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// do something here when it starts to refresh
// e.g. to request data from server
}
});
//set RefreshCheckHandler (OPTIONAL)
mCustomSwipeRefreshLayout.setRefreshCheckHandler(new CustomSwipeRefreshLayout.RefreshCheckHandler() {
@Override
public boolean canRefresh() {
// return false when you don't want to trigger refresh
// e.g. return false when network is disabled.
}
});
// to tell the CustomSwipeRefreshLayout when your refreshing process is complete
// e.g. when received data from server
mSwipeRefreshLayout.refreshComplete();
// to handle scrolling up event
mCustomSwipeRefreshLayout.setScrollUpHandler(new CustomSwipeRefreshLayout.ScrollUpHandler() {
@Override
public boolean canScrollUp(View view) {
// e.g. check whether the scroll up event can be consumed by the RecyclerView
if (view == mRecyclerView){
return ((GridLayoutManager)mLayoutManager).findFirstCompletelyVisibleItemPosition() != 0;
}
return false;
}
});
// to handle scrolling left of right event
mCustomSwipeRefreshLayout.setScrollLeftOrRightHandler(new CustomSwipeRefreshLayout.ScrollLeftOrRightHandler() {
@Override
public boolean canScrollLeftOrRight(View view, int direction) {
// e.g. check whether the scroll left or right event can be consumed by your Custom View
if (view == myCustomView){
return myCustomView.canScrollHorizontal(direction);
}
return false;
}
});
我只是想发布链接,但SOF不允许我这样做。下面是链接我们是否可以将自定义动画设置为SwipereFreshLayout您可以在com.reginald.swiperefresh.CustomSwipeRefreshLayout中进行所需的更改