Search code examples
androidandroid-listviewandroid-cardviewbottomnavigationview

Add bottom info bar after the last Card usingCardView


Im looking to achieve something like on the image.

I want to add some view element (it really doesn't matter, it could be TextView,Button, whatever) to the bottom of the screen (above my BottomNavigationBar) to show some info (orange area in the picture). I tried to implement BottomAppBar but this bar belongs to every card in the card view, but I want it to be displayed only once after the last card presented.

Here is my XML of that view:

<?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>

I tried to implement some logic in my adapter class like:

@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(...);
           }
      }

but no luck. Could you please give me any advice or maybe there is some element for that purpose? Thank you.


Solution

  • Ive made this by adding different types of ViewHolder’s of my RecyclerView and according to its types, create additional itemview for footer (or header). If someone needs more information - tell me and ill paste my code here.