需求:数据修改后,将RecyclerView中部分item隐藏,达到不可见效果,但不是data的remove,隐藏的item,还能再可见。
问题:设置setVisibility(View.GONE)后,出现空白高度。
解决:将item的根布局下写一个子布局,子布局中包含item的所有控件,隐藏的时候,将子布局隐藏即可。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/HideRelativeLayout"
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="10dp"
android:background="@drawable/item_bk">
<!--item中的内容-->
</RelativeLayout>
</RelativeLayout>
data中有个ifShow的数据,当ifShow为true时候,执行HideRelativeLayout.setVisibility(View.VISIBLE),即可见,当ifShow为false时候,便执行HideRelativeLayout.setVisibility(View.GONE),即可隐藏,上面的解决方法亲测使用,