2016-08-29 3 views
0

solution을 기반으로하는 데이터 바인딩을 통해 RecyclerView에 대한 빈 뷰 솔루션을 구현하려고합니다. SwipeRefreshLayout 내에 RecyclerView와 RelativeLayout (빈 뷰)가 있습니다. 자신의 visbilities가 SeriesList 인 데이터 세트의 크기를 기반으로 RecyclerView이 빈보기 후 당신은 RelativeLayout의를 볼 수있는RecyclerView의 빈 뷰에 대한 데이터 바인딩 가시성이 적용되지 않음

<layout xmlns:android="http://schemas.android.com/apk/res/android"> 
    <data> 
     <import type="android.view.View"/> 
     <variable 
      name="dataset" 
      type="...SeriesList"/> 
    </data> 
    <android.support.v4.widget.SwipeRefreshLayout 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/swipe_refresh_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.v7.widget.RecyclerView 
      xmlns:tools="http://schemas.android.com/tools" 
      android:id="@+id/list" 
      android:name="...SeriesFragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="2dp" 
      android:layout_marginRight="2dp" 
      android:layout_marginTop="10dp" 
      app:layoutManager="LinearLayoutManager" 
      tools:context=".fragments.SeriesFragment" 
      android:visibility="@{dataset.size() > 0 ? View.VISIBLE : View.GONE}"/> 

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/empty_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:visibility="@{dataset.size() > 0 ? View.GONE : View.VISIBLE}"> 

      <TextView 
       android:id="@+id/empty_text" 
       style="@style/Base.TextAppearance.AppCompat.Title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/empty_image" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="10dp" 
       android:width="300dp" 
       android:gravity="center" 
       android:textColor="#59000000" /> 

      <ImageView 
       android:id="@+id/empty_image" 
       android:layout_width="128dp" 
       android:layout_height="160dp" 
       android:layout_centerInParent="true" 
       android:src="@drawable/empty" /> 
     </RelativeLayout> 
    </android.support.v4.widget.SwipeRefreshLayout> 
</layout> 

이 (ObservableArrayList를 확장) 다음은 레이아웃의 XML입니다. 나는 어댑터의 볼 SeriesList이 비어있을 때 RecyclerView의 가시성이 사라지고 빈보기됩니다 있으리라 믿고있어 그래서이의 기반으로

FragmentSeriesListBinding binding = FragmentSeriesListBinding.inflate(inflater); 
    binding.setDataset(getmAdapter().getVisibleSeries()); 

:이 레이아웃을 포함하는 단편에서 나는 그래서 같은 데이터를 바인딩 VISIBLE이 될 것입니다. 빈 데이터 집합으로 테스트 할 때 RecyclerView (항목 없음)와 빈보기 모두 VISIBLE의 가시성을 가지므로 불가능합니다. 누군가 내가 기대 한대로 작동하지 않는 이유에 대해 약간의 빛을 비춰 줄 수 있습니까?

답변

0

그래서 우리는 here을 읽은 후이를 고쳤다. SwipeRefreshLayout은 하나의 자식을 가져야하므로 FrameLayout에 RecyclerView와 RelativeLayout을 래핑했다. 또한 this 솔루션을 사용하여 Fragment의 레이아웃을 DataBindingUtil inflate() 메서드로 확장하고 Fragment의 onCreateView() 메서드에서 바인딩을 설정했습니다.