ScrollView嵌套Relative时候会发生问题,RelativeLayout不会充满ScrollView,即使设置match_parent属性也不行

这个时候就需要fillViewPort属性登场了,在ScrollView的源码的onMeasure中,专门针对这个属性做了特殊的处理


protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (!mFillViewport) {
return;
} final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
if (heightMode == MeasureSpec.UNSPECIFIED) {
return;
} if (getChildCount() > 0) {
final View child = getChildAt(0);
final int widthPadding;
final int heightPadding;
final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
final FrameLayout.LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (targetSdkVersion >= VERSION_CODES.M) {
widthPadding = mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin;
heightPadding = mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin;
} else {
widthPadding = mPaddingLeft + mPaddingRight;
heightPadding = mPaddingTop + mPaddingBottom;
} final int desiredHeight = getMeasuredHeight() - heightPadding;
if (child.getMeasuredHeight() < desiredHeight) {
final int childWidthMeasureSpec = getChildMeasureSpec(
widthMeasureSpec, widthPadding, lp.width);
final int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(
desiredHeight, MeasureSpec.EXACTLY);
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
}
}
}

ScrollView的fillViewPort属性的更多相关文章

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

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

  2. 小程序用scroll-view的scroll-to-view属性实现锚链接跳转

    小程序没有锚链接,通过scroll-view可以实现类似锚链接的功能,点击锚链接,滚动条滚动到相应的位置 wxml <view class="wrap"> <!- ...

  3. 微信小程序 - scroll-view的scroll-into-view属性 - 在页面打开后滚动到指定的项

    需求: 这是一个可横向滚动的导航条,现在要求我,从别的页面reLaunch回到首页这里,刷新页面内容的同时,菜单项要滚动出来 (如果该菜单项不在可视区域),而不是让他被挡住. 代码:<scrol ...

  4. Android ScrollView内部组件设置android:layout_height="fill_parent"无效的解决办法

    问题:scrollview内部组件都设置了android:layout_height="fill_parent"却没有效果. 解决办法:设置scrollview的fillViewp ...

  5. Android:ScrollView和SwipeRefreshLayout高度测量

    今天组里的同事要做一个奇葩的效果,要求在ScrollView里嵌套一个RefreshLayout.类似代码如下: <?xml version="1.0" encoding=& ...

  6. android:fillViewport="true"让ScrollView内的view强行match_parent

    当你想让一个高度值不足scrollview的子控件fillparent的时候,单独的定义android:layout_height="fill_parent"是不起作用的,必须加上 ...

  7. 实现ScrollView中包含ListView,动态设置ListView的高度

    ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...

  8. android ScrollView 充满屏幕

    android:fillViewport=true ScrollView下面的组件如果有android:layout_height="fill_parent"或android:la ...

  9. ScrollView的顶部下拉和底部上拉回弹效果

    要实现ScrollView的回弹效果,需要对其进行触摸事件处理.先来看一下简单的效果: 根据Android的View事件分发处理机制,下面对dispatchTouchEvent进行详细分析: 在加载布 ...

随机推荐

  1. style控制打印分页

    [转载地址:http://www.cnblogs.com/JustinYoung/articles/710734.html]page-break-before和page-break-after CSS ...

  2. 安装你自己的perl modules

    来源: http://www.cnblogs.com/itech/archive/2012/12/17/2822044.html 安装你自己的perl modules.当没有root权限的时候,需要安 ...

  3. maven之pom

    记录一下最近的pom的相关设置,plugin的官方地址配置:http://maven.apache.org/plugins/index.html 看了网上说了很多例子,有很多不清楚,看一下官方的,会有 ...

  4. docker certificates

    x509: certificate is valid for mmtrkjy.com, *.mmtrkjy.com, *.mmtrkmc.com, *.mmtrkpd.com, *.mmtrksg.c ...

  5. spice up your desktop

    https://wiki.gnome.org/Projects/GnomeShell/CheatSheet windows10用了一段时间,回来看着gnome3-shell是那么的恶心,翻来翻去重新整 ...

  6. SQL Server 2008 2005删除或压缩数据库日志的方法

    由于数据库日志增长被设置为“无限制”,所以时间一长日志文件必然会很大,一个400G的数据库居然有600G的LOG文件,严重占用了磁盘空间.由于主要是做OLAP,所以数据库本身不会有大变动,所以日志也就 ...

  7. ignite客户端找不到服务端的时候如何设置退出

    ignite启动客户端时需要有服务端支持: Ignition.setClientMode(true); Ignition.start("ignite.xml"); 这里有个问题,当 ...

  8. Css 之 px em %

    在页面整体布局中,页面元素的尺寸大小(长度.宽度.内外边距等)和页面字体的大小也是重要的工作之一.一个合理设置,则会让页面看起来层次分明,重点鲜明,赏心悦目.反之,一个不友好的页面尺寸和字体大小设置, ...

  9. 织梦DEDE文章列表前面自动加递增数字标签

    实现的办法很简单,只须要在序号递增的处所加上这段代码就行 [field:global runphp=""yes"" name=autoindex][/field ...

  10. Android中的对话框AlertDialog使用技巧合集-转载

    Android中的对话框AlertDialog使用技巧合集     文章来自:http://blog.csdn.net/blue6626/article/details/6641105   今天我用自 ...