不知道打家在用SwipeRefreshLayout来做下拉刷新时有没有遇到过这么个情况:在需要在列表没有数据时显示个提示,有数据时显示数据。别看很简单,然而SwipeRefreshLayout并不让你简单。。。她不许你放两个控件切换啊啊啊啊啊啊啊啊!!!!!!!好吧,还是得再加个布局容器,以下是我目前验证了各个用法后得到方法:
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefresh" android:layout_width="match_parent" android:layout_height="match_parent" > <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="@{dataNull ? View.INVISIBLE:View.VISIBLE}" android:paddingEnd="10dp" android:paddingStart="10dp" android:overScrollMode="never" android:adapter="@{adapter}" app:layoutManager="android.support.v7.widget.LinearLayoutManager" /> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:visibility="@{dataNull ? View.VISIBLE:View.INVISIBLE}" android:textColor="#80000000" android:textSize="20sp" android:text="@string/record_null_txt"/> </FrameLayout> </android.support.v4.widget.SwipeRefreshLayout>
这样才能完美的实现,没有数据时可以给个提示,还可以刷新一下,有数据时就显示数据。