原文:https://blog.csdn.net/glmxzaj/article/details/50774616
今天在做项目时用到ScrollView,我发现如果在ScrollView控件之后没有别的布局时它能正常滑动.但是如果我在ScrollView之后又加了一个布局,比如我在屏幕最底部加了一个RelativeLaout 时ScrollView就不能滑动了.
下面我说下我的解决办法: 大家先看下我原来的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EEEEEE" >
<include
android:id="@+id/top_commit_order"
layout="@layout/base_top_layout" />
<ScrollView
android:id="@+id/sv_commit_order"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top_commit_order"
android:layout_marginBottom="15dp"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</RelativeLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/rl_commit_order"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="49dp"
android:background="@color/white" >
</RelativeLayout>
</RelativeLayout>
这个样子是不行的,我通过在网上搜索发现了以下结局办法,以下是更改后的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EEEEEE" >
<include
android:id="@+id/top_commit_order"
layout="@layout/base_top_layout" />
<RelativeLayout
android:id="@+id/rl_commit_order"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="49dp"
android:background="@color/white" >
</RelativeLayout>
<ScrollView
android:id="@+id/sv_commit_order"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top_commit_order"
android:layout_above="@id/rl_commit_or"
android:layout_marginBottom="15dp"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
大家发现没,我是把底部的布局移动到ScrollView上面了,并在ScrollView中加入了一个属性 android:layout_above="@id/rl_commit_or",rl_commit_or正是底部的布局如此便能够滑动了
解决Android ScrollView嵌套RecyclerView出现数据展示不全及滑动卡顿问题
https://blog.csdn.net/a_kevin/article/details/86629758