我已經在我的列表視圖之一上實現了刷卡刷新佈局,但是當我滑動並且圖標不可見時,視圖不會滑落。即使它看起來不起作用,它確實會觸發OnRefresh偵聽器。刷新刷新佈局onRefresh工作但不顯示刷新指示器
另外我覺得值得一提的是我在一個片段上使用了ListView,因此我正在初始化下面顯示的片段活動中的監聽器。
刷卡刷新XML
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView"
android:layout_gravity="center_horizontal"
android:dividerHeight="1sp"
android:translationZ="5dp"
android:background="@color/background_gray"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
/>
</android.support.v4.widget.SwipeRefreshLayout>
片段活動
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) getActivity().findViewById(R.id.swipe_refresh_layout);
ListView lView = (ListView) getActivity().findViewById(R.id.listView);
mSwipeRefreshLayout.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);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mSwipeRefreshLayout.setRefreshing(true);
((MainActivity) getActivity()).refresh();
new Handler().postDelayed(new Runnable() {
@Override public void run() {
mSwipeRefreshLayout.setRefreshing(false);
}
}, 5000);
}
});
lView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (firstVisibleItem == 0)
mSwipeRefreshLayout.setEnabled(true);
else
mSwipeRefreshLayout.setEnabled(false);
}
});
}
也許這將幫助:http://stackoverflow.com/questions/26858692/swiperefreshlayout-setrefreshing-not-showing-indicator-initially – Kay
感謝@Kay但這並不解決任何的問題我。該線程上的解決方案與我目前的解決方案一樣。 –