SwipeRefreshLayout
フラグメントの 1 つにレイアウトを追加しようとしています。リストにいくつかの要素が含まれている場合、すべてが期待どおりに機能します。
問題は、リストが空の場合です。ViewStub
リストにアイテムが含まれていないときに表示されますが、その時点でトリガーOnRefreshListener
されることはありません。
これが私の ListFragment xml です。
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRenewals"
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="@android:id/list"
android:fadingEdge="vertical"
android:layout_gravity="center"
android:cacheColorHint="@android:color/transparent"/>
<ViewStub
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout="@layout/empty_renewal"/>
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>
そして、ViewStub にロードするレイアウト:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"/>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/ic_warning"
android:adjustViewBounds="true"
android:layout_weight="1" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/no_renewal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/refresh_for_new"/>
</LinearLayout>
リストが空のときにスワイプジェスチャーでリフレッシュをトリガーする方法はありますか?