【问题标题】:Add bottom info bar after the last Card usingCardView使用CardView 在最后一张卡片后添加底部信息栏
【发布时间】:2020-01-28 08:13:20
【问题描述】:

我想在屏幕底部(在我的 BottomNavigationBar 上方)添加一些视图元素(真的没关系,可能是TextViewButton,等等)以显示一些信息(在图片)。我尝试实现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(...);
           }
      }

但没有运气。 你能给我任何建议吗,或者也许有一些为此目的的元素?谢谢。

【问题讨论】:

  • 您可以将列表中的项目添加为底栏,当您获取数据并添加到列表中时,然后在列表中添加任何小部件的项目
  • @Avinash 就像我上面提到的那样,我已经尝试过这个技巧,但是每张卡都附有底栏
  • 你在哪里添加自定义项?
  • @Avinash 这有关系吗?你的问题对你来说很重要,还是你无缘无故地问?
  • 如果您从服务器获取,那么当您再次通过分页获取列表时,删除最后一项并再次添加。

标签: android android-listview android-cardview bottomnavigationview


【解决方案1】:

我通过添加我的RecyclerView 的不同类型的 ViewHolder 并根据其类型为页脚(或页眉)创建额外的 itemview 来实现这一点。如果有人需要更多信息 - 请告诉我并将我的代码粘贴到此处。

【讨论】:

    猜你喜欢
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多