我在添加自定义空视图代替布局中的recyclerview时遇到了一些问题。我的自定义空视图的重力为" center_vertical"。当我像这样添加它时,自定义空视图中添加的图像和文本隐藏在显示列表视图的区域下方。它正在离开屏幕。我认为这是因为" appbar_scrolling_view_behavior"对于SwipeRefreshLayout。但我需要这样做,以便appbar在列表滚动时滚动。但如果没有数据可供显示,我希望自定义空视图中的图像显示在屏幕中央的appbarlayout下方。目前它被推到屏幕的底部。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/headRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
app:layout_scrollFlags="scroll|enterAlways">
<include
android:id="@+id/topLayout"
layout="@layout/top_sch_listview" />
<include
android:id="@+id/msgLayout"
layout="@layout/view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/topLayout" />
<include
android:id="@+id/subHeaderLayout"
layout="@layout/view_sub_header"
android:layout_width="match_parent"
android:layout_height="@dimen/sub_header_height"
android:layout_below="@+id/msgLayout" />
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.my.views.CustomEmptyView
android:id="@+id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
<View
android:id="@+id/blankView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
</android.support.design.widget.CoordinatorLayout>
我不确定我做错了什么。有人可以帮忙吗?
感谢。
答案 0 :(得分:-1)
CustomEmptyView删除
recyclerListView 两个ViewHoler在adpater中的设置
emptyView holder&gt; (自定义空视图)
DataView Holder&gt; (RecycleView:List)
public class AdvancedItemAdapter extends MultiItemAdapter {
public static final int VIEW_TYPE_EMPTY = 0;
public static final int VIEW_TYPE_DATA = 1;
@Override
public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == VIEW_TYPE_EMPTY) {
EmptyViewHolder holder = (EmptyTYpeViewHolder)viewHolder;
return holder;
} else {
DataViewHolder holder = (DataTYpeViewHolder)viewHolder;
return holder;
}
}
}
数据阵列计数检查
notifyDataSetChanged上一页
setType(标记,视图类中的类型值)
适配器notifyDataSetChanged()