簡體   English   中英

刷新刷新布局onRefresh工作但不顯示刷新指示器

[英]Swipe Refresh Layout onRefresh working but not displaying refresh indicator

我已經在我的一個列表視圖上實現了一個刷卡刷新布局,但是當我滑動並且圖標不可見時,視圖不會向下滑動。 即使看起來它不起作用,它確實會觸發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);
        }
    });

}

我解決了它,看來這是SwipeRefreshLayout的當前錯誤。 它僅在Listview包含在FrameLayout中時才有效。

<?xml version="1.0" encoding="utf-8"?>

<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">
    <FrameLayout
        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"
        />
    </FrameLayout>

</android.support.v4.widget.SwipeRefreshLayout>

只需為SwipeRefreshLayout的Immediate clild布局設置屬性[ android:clickable =“true” ],該布局占用完整的屏幕區域。其寬度和高度為match_parent。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/srlayout_Container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true">

        <RelativeLayout
            android:id="@+id/rl_MainContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="true">
            <!-- Placeholder for Other View or ViewGroup as Clild -->
        </RelativeLayout>
    </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM