使用 CardView 在最后一张 Card 之后添加底部信息栏
Add bottom info bar after the last Card usingCardView
我想在屏幕底部(我的 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>
我试图在我的适配器中实现一些逻辑 class 例如:
@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 来做到这一点,并根据其类型,为页脚(或页眉)创建额外的项目视图。如果有人需要更多信息 - 告诉我并在此处粘贴我的代码。
我想在屏幕底部(我的 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>
我试图在我的适配器中实现一些逻辑 class 例如:
@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 来做到这一点,并根据其类型,为页脚(或页眉)创建额外的项目视图。如果有人需要更多信息 - 告诉我并在此处粘贴我的代码。