BottomNavigationView切换含ScrollView的FrameLayout时滚动失效求助
我帮你定位到问题根源了!你的ScrollView不能正常滚动,核心问题出在activity_main.xml里的FrameLayout高度设置上——你给它设成了wrap_content,这会导致FrameLayout的高度完全跟随内部ScrollView的内容高度,ScrollView自身高度和内容高度一致,自然就没有滚动的必要了。
修复步骤:
只需要把activity_main.xml中FrameLayout的android:layout_height从wrap_content改成match_parent即可,这样FrameLayout会占据顶部到BottomNavigationView之间的全部可用空间,ScrollView就能在这个固定高度的容器内正常滚动了。
修改后的activity_main.xml代码:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.panel.roubook.activities.NewBook"> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" <!-- 这里修改为match_parent --> android:layout_above="@+id/bottom_navigation" android:layout_alignParentTop="true"> </FrameLayout> <android.support.design.widget.BottomNavigationView android:id="@+id/bottom_navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" app:itemBackground="@color/colorAccent" app:itemIconTint="@color/colorPrimary" app:itemTextColor="@color/colorPrimary" app:menu="@menu/navigation_items" /> </RelativeLayout>
额外验证点:
- 确认你的ScrollView的
android:layout_height保持match_parent(你已经设置正确了) - 内部LinearLayout的高度保持
wrap_content,这样ScrollView才能识别内容超出容器高度,触发滚动逻辑
这样修改后,你的ScrollView就能正常滚动啦!
内容的提问来源于stack exchange,提问作者dieroste
相关产品推荐
相关产品推荐

