NestedScrollView被底部View遮挡的问题

weixin_42004869 2018-08-07 01:32:43
我想实现Bottom Navigation的效果,因此想在布局底部增加一个被LinearLayout包含的View,但是当NestedScrollView中嵌套了一个RecyclerView,而且RecyclerView的item的数量大于屏幕能容纳的数量时,最后一个item会被底部的View遮挡,就像这样:


我尝试在NestedScrollView中添加layout_marginBottom的属性,但是依然无效。我想问问怎样才能使得底部View不会把RecyclerView的最后一个Item遮住?谢谢!

这是我的xml代码,关键代码我已经标明了:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true">

<ImageView
android:id="@+id/backgroud_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"/>

<android.support.v7.widget.Toolbar
android:id="@+id/mainactivity_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<!-- 关键代码从这里开始... ... -->

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="56dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<android.support.v7.widget.RecyclerView
android:id="@+id/music_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</android.support.v4.widget.NestedScrollView>

<LinearLayout
android:id="@+id/music_bottom"
android:layout_width="match_parent"
android:layout_height="56dp"
android:elevation="2dp"
android:background="#fff"
android:layout_gravity="bottom"
android:orientation="horizontal">


</LinearLayout>

<!-- 关键代码在这里结束... ... -->

<android.support.design.widget.FloatingActionButton
android:id="@+id/mainactivity_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_music_note_white_24dp"
android:layout_margin="16dp"
app:layout_anchor="@id/appBar"
app:layout_anchorGravity="bottom|end"
app:rippleColor="#5bc406"
app:borderWidth="1dp"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
android:translationZ="6dp"
android:clickable="true"/>

</android.support.design.widget.CoordinatorLayout>

...全文
682 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
影空 2019-11-08
  • 打赏
  • 举报
回复
楼主发现有没有其它解决方式呢。
键盘舞者113 2018-08-08
  • 打赏
  • 举报
回复
不影响性能,因为你这个view其实没有画任何东西,只是占住了一部分位置而已
weixin_42004869 2018-08-07
  • 打赏
  • 举报
回复
引用 1 楼 z979451341 的回复:
你在RecyclerView里最后加载一个和bottombar等高的layout的item,通过itemtype区别加载


我尝试了你的方法,成功了

我还有一个问题,我在RecyclerView下方加了一个空的View,像这样

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="56dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
android:id="@+id/music_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<View
android:layout_width="match_parent"
android:layout_height="56dp"/>

</LinearLayout>

</android.support.v4.widget.NestedScrollView>

这样也成功了。在实际中能不能这样做,性能影响大吗?
键盘舞者113 2018-08-07
  • 打赏
  • 举报
回复
你在RecyclerView里最后加载一个和bottombar等高的layout的item,通过itemtype区别加载

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧