2

SwipeRefreshLayout 레이아웃을 제 조각에 추가하려고합니다. 목록에 일부 요소가 포함되어 있으면 예상대로 작동합니다.SwipeRefresh 레이아웃이 사용자 정의 빈 목록보기와 작동하지 않습니다.

내 목록이 비어있는 경우 문제가 발생합니다. 목록에 항목이 없을 때 ViewStub이 나타나고 그 시점에서 OnRefreshListener이 실행되지 않습니다. 나는 ViewStub에로드

<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> 

그리고 레이아웃 :

<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> 

그래서 내가 할 수있는 방법이 여기에

내 ListFragment의 XML입니다 목록이 비어있을 때 스 와이프 동작으로 새로 고침을 실행 하시겠습니까?

답변

3

명백하게 문제를 작성하는 것이 도움이되었습니다.

내 ViewStub 레이아웃을 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>