2

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>

リストが空のときにスワイプジェスチャーでリフレッシュをトリガーする方法はありますか?

4

1 に答える 1

3

どうやら問題を書き留めることが助けになったようです。

ViewStub Layout を ScrollView にカプセル化することで問題を解決しました。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        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>
</ScrollView>
于 2014-05-16T21:55:54.043 に答える