我想在recyclerview的底部添加具有空布局的页脚,只有在屏幕上看到某些视图时才会显示(在我的例子中是fabbutton)。FabButton与上一个RecyclerView项目重叠,因此如果此FabButton可见,我希望将空页脚添加到RecyclerView的底部。
页脚适配器内的取景器:
inner class FooterViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
在OnBindViewholder内:
... ViewHolder above is for items.
else if(holder is FooterViewHolder){
if (parentFragment.isFabButtonVisible()){
holder.itemView.visibility = View.VISIBLE
} else {
holder.itemView.visibility = View.GONE
}
}
代码的这一部分正在工作(其他分支也可以正确执行),但我的页脚视图在屏幕上是永久可见的。即使我只添加
View.GONE
它仍然可见。
父活动的XML:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/splash_white"
android:layout_weight="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
>
<com.app.TabLayoutEntity.CustomViewPager
android:id="@+id/fragmentViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@color/splash_white"
tools:layout_editor_absoluteY="-2dp" />
<ImageButton
android:id="@+id/fabButton"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:background="@drawable/fab_gradient"
android:clickable="true"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:padding="8dp"
android:elevation="8dp"
android:shape="oval"
android:src="@drawable/ico_fab" />
</android.support.design.widget.CoordinatorLayout>
片段XML(在viewpager中):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clipToPadding="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/itemRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/recyclerview_corners"
android:clipToPadding="false"
android:scrollbars="vertical"
android:paddingBottom="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>