Recyclerview 在 CoordinatorLayout 中不太可见
我正在开发一个应用程序使用RecyClerview来显示用户的费用,但是我面临的问题是,在滚动下方滚动后滚动后滚动后没有看到内容。 此图像解释了我的问题:
这是我的布局:
< androidx.coordinatorLayout.widget.coordinatorlayout,
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/transparent"
android:backgroundTint="@color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.AppUiActivity">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_gravity="bottom"
android:gravity="center"
app:backgroundTint="@color/blue_900"
android:baselineAligned="false"
app:fabCradleMargin="3dp"
app:fabCradleRoundedCornerRadius="40dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:hideOnScroll="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:id="@+id/categories"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="3"
android:clickable="true"
android:background="?android:selectableItemBackground"
android:gravity="center"
android:focusable="true">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="4dp"
android:text="@string/categories"
android:textSize="11.5sp"
android:fontFamily="@font/crafty_girls"
android:textStyle="bold"
android:textColor="@color/white"
app:drawableTopCompat="@drawable/ic_expense" />
</LinearLayout>
<LinearLayout
android:id="@+id/details"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="3"
android:clickable="true"
android:focusable="true"
android:background="?android:selectableItemBackground"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="4dp"
android:text="@string/details"
android:textSize="12sp"
android:textStyle="bold"
android:fontFamily="@font/crafty_girls"
android:textColor="@color/white"
app:drawableTopCompat="@drawable/ic_details" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="3"
android:enabled="false"
android:background="?android:selectableItemBackground"
android:gravity="center" />
<LinearLayout
android:id="@+id/calculate"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:clickable="true"
android:focusable="true"
android:layout_weight="3"
android:background="?android:selectableItemBackground"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="5dp"
android:text="@string/calculate"
android:textStyle="bold"
android:textSize="12sp"
android:fontFamily="@font/crafty_girls"
android:textColor="@color/white"
app:drawableTopCompat="@drawable/ic_calculator" />
</LinearLayout>
<LinearLayout
android:id="@+id/total"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="?android:selectableItemBackground"
android:layout_gravity="center"
android:clickable="true"
android:focusable="true"
android:layout_weight="3"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="4dp"
android:text="@string/total"
android:textSize="12sp"
android:textStyle="bold"
android:fontFamily="@font/crafty_girls"
android:textColor="@color/white"
app:drawableTopCompat="@drawable/ic_money" />
</LinearLayout>
</LinearLayout>
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:clickable="true"
android:contentDescription="@string/add_expenses"
android:elevation="20dp"
android:focusable="true"
app:fabSize="normal"
app:layout_anchor="@id/bottom_bar"
app:layout_anchorGravity="center"
app:srcCompat="@drawable/ic_add"
tools:ignore="ImageContrastCheck" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
所以我需要一个有用的答案,因为我已经在处理这个问题了一个星期,但是没有解决方案然而。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需向您的 recyclerview 添加 2 个属性即可
当您位于列表底部时,
,只有这些属性才会生效,并且它将添加 50 dp 的额外填充,以便 recyclerview 在底部有更多的区域可以滚动。快乐编码!
Just add 2 properties to your recyclerview
when you are at bottom of the list than only these property comes in effect and it will add 50 dp additional padding so that recyclerview have more area at bottom to scroll.
Happy coding!!!
计算了Bottombar的高度后在运行时添加底部填充时,而不是在XML上猜测Marginbottom的最佳方法。
Java中
在Kotlin的
,您还需要将以下属性添加到您的recyclerview中,以便可以看到您的回收范围元素在底部的Appbar后面滚动:
Instead of guessing on marginBottom on XML best way to perform this by adding bottom padding at runtime after height for the BottomBar is calculated.
In Java
In Kotlin
You need to also add following attribute to your RecyclerView so that your Recyclerview elements are seen scrolling behind your bottom appbar:
为回收器视图添加边距底部,如下所示,这将在
BottomAppBar
上方提供列表 预览在这里:https://i.sstatic.net/Kf809.png
Add margin bottom for the recycler view as shown below this will give the list above the
BottomAppBar
Preview is here : https://i.sstatic.net/Kf809.png