我想在屏幕底部(在我的BottomNavigationBar上方)添加一些视图元素(这没关系,可以是TextView
,Button
,无论如何)以显示一些信息(图片)。我尝试实现BottomAppBar,但是此栏属于卡视图中的每张卡,但我希望在显示最后一张卡之后仅将其显示一次。
这是该视图的XML:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView android:id="@+id/basket_view"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:cardCornerRadius="10dp"
app:cardElevation="2dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:strokeWidth="2dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraint_layout"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:layout_width="match_parent">
<ImageView
android:adjustViewBounds="true"
android:id="@+id/basket_image"
android:layout_height="72dp"
android:layout_width="110dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/ic_launcher" />
<TextView
style="@style/TextAppearance.MaterialComponents.Headline6"
android:id="@+id/comp_title"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_width="wrap_content"
android:text="description"
app:layout_constraintStart_toEndOf="@+id/basket_image"
app:layout_constraintTop_toTopOf="@+id/basket_image" />
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.TextButton"
android:id="@+id/remove_btn"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_width="wrap_content"
android:text="@string/remove"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/basket_image"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="@+id/some_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="anotherInfo"
app:layout_constraintBottom_toBottomOf="@+id/remove_btn"
app:layout_constraintStart_toStartOf="@+id/comp_title" />
<TextView
android:id="@+id/some_text_value"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_width="wrap_content"
android:text="someTxt"
app:layout_constraintStart_toEndOf="@+id/some_title"
app:layout_constraintTop_toTopOf="@+id/some_title" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
我试图在我的适配器类中实现一些逻辑,例如:
@Override
public void onBindViewHolder(@NonNull OrderRecyclerViewHolder holder, int position) {
holder.bind(data, position);
}
public void bind(Data data, int position) {
if (data != null) {
if(data.size() == (position + 1)) {
//some methods to set bottom bar to be Visible
}
compTitle.setText(...);
basketImage.setBackgroundResource(...);
}
}
但没有运气。您能否给我任何建议,或者为此目的提供一些要素?谢谢。
我通过添加RecyclerView
的不同类型的ViewHolder,并根据其类型为页脚(或页眉)创建了额外的itemview来完成此操作。如果有人需要更多信息-告诉我,请在这里粘贴我的代码。