ScrollView fillViewport 使用

有一个需求

  1. 界面中自上而下有两个方块,依次为A、B方块。
  2. A 方块的大小不固定,小的时候在屏幕内,大的时候会超过屏幕外。
  3. B 的布局,始终在A的下方,屏幕够显示时,在屏幕的最底部,屏幕不够显示时,随着A滑动。

fillViewport 引入

如果只在外层写了ScrollView,B会紧紧跟随A,B 不会始终在屏幕最底部了。
这时在 ScrollView 内加入 fillViewport=true, 就可以实现需求了。

效果图 与 layout 测试代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity"><ScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:fillViewport="true"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:background="@color/colorAccent"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:background="@color/colorPrimary"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_width="100dp"android:layout_height="200dp"android:layout_alignParentBottom="true"android:background="@mipmap/ic_launcher" /></RelativeLayout></LinearLayout></ScrollView></LinearLayout>

ScrollView fillViewport 使用相关推荐

  1. [Android Pro] ScrollView使用fillViewport设置高度为MatchParent

    reference to : http://blog.csdn.net/u012975705/article/details/49275001 之前遇到一问题,就是当使用ScrollView时,Scr ...

  2. ScrollView’s handy trick--android:fillViewport=quot;truequot;

    ScrollView is one of Android's most commonly used widget and is also one of the easiest to use. When ...

  3. scrollView的fillviewport

    Romain Guy write a little info about a ScrollView attribute that is missing  from documentation : an ...

  4. ScrollView 内嵌 ListView 只能看到第一个Item

    解决方案: 给ScrollView 设置 fillViewport 为 true,ListView 就不会只显示第一个了. <ScrollView xmlns:android="htt ...

  5. ScrollView充满屏幕

    <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android=" ...

  6. 四种方案解决ScrollView嵌套ListView问题

    在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollView嵌套ListView结 ...

  7. ScrollView中的LinearLayout不能使用android:layout_heig...

    2019独角兽企业重金招聘Python工程师标准>>> ScrollView中的LinearLayout不能使用android:layout_height="fill_pa ...

  8. ScrollView’s handy trick

    ScrollView is one of Android's most commonly used widget and is also one of the easiest to use. When ...

  9. android中ScrollView嵌套ListView或GridView显示位置问题

    Android中ScrollView中嵌套ListView或GridView时在开始进入界面时总是显示中间位置,开头的位置显示不出来.这种情况下只需要在ScrollView的父控件中添加以下两行代码即 ...

最新文章

  1. 23种设计模式之单例模式
  2. Python 图像 一样大小_Python图像处理,顺便生成一张海报
  3. Matlab与神经网络入门
  4. 004-cpu的区分
  5. 【数据迁移】使用传输表空间迁移数据
  6. 查看windosw服务器序列号,型号
  7. WinXP的EFS加密文件如何解密?
  8. 软件测试--缺陷报告
  9. request,response传入线程值会变为null
  10. jpython 传入参数_C++嵌入Python程序(二):参数传入及返回
  11. Matlab R2019a Win64位 迅雷下载链接
  12. 计算机一级考试 文字录入,计算机一年级《文字录入》期末考试题(理论)B
  13. Stuck Stack成过去时,OpenStack升级还可以这样玩?!
  14. Android应用向su申请root权限,以及Superuser进行授权管理的原理浅析
  15. CMMI推广中EPG常犯错误
  16. putty小键盘输入_putty或xshell上用vi/vim小键盘无法使用的解决方法-阿里云开发者社区...
  17. 航芯技术分享 | 一文读懂什么是量子密码
  18. 音乐API调用以及分析(以酷狗音乐为例)
  19. C# VLC视频播放器
  20. 蓝牙协议与普通网络协议的对比

热门文章

  1. Web系统与技术概述
  2. 毕业差不多一年,跳槽华为od岗,已入职
  3. html 上下广告悬浮,JS上下自动漂浮广告,可关闭
  4. USB设备绑定固定端口
  5. 什么人间悲剧,面试被刷了还要被HR怼.....
  6. vue中嵌套页面(iframe)
  7. 【转载】Ubuntu下安装配置OpenNI, OpenCV(来自韶子空间)
  8. python鼠标键盘同时监听
  9. 小米9升级安卓10体验
  10. Android集成阿里百川(AndroidStudio 4.2.1+gradle 6.7.1+gradle tool 4.2.1)