当前位置: 首页 > news >正文

做电子政务网站电脑培训网上培训班

做电子政务网站,电脑培训网上培训班,沈阳网站开发公司,html制作动态网页留言板代码前言 此场景为 NestedScrollView 嵌套多个布局 ,大致结构为 NestedScrollViewTabLayoutViewPagerfragment 其它View,如下图 , 一、ViewPager 设置高度才会显示内容问题 原因:NestedScrollView 计算高度先于 ViewPager 渲染前,所…

前言

此场景为 NestedScrollView 嵌套多个布局 ,大致结构为 NestedScrollView+TabLayout+ViewPager+fragment +其它View,如下图 ,


一、ViewPager 设置高度才会显示内容问题

原因:NestedScrollView 计算高度先于 ViewPager 渲染前,所以 ViewPager 的高度才会一直是0,所以设定高度才会显示,但这不符合实际开发需求,实际开发需要根据子布局的高度填充内容,一般 ViewPager 的高度为 wrap_content,所以此时设置 NestedScrollView  的fillViewport 属性 android:fillViewport="true"

    <android.support.v4.widget.NestedScrollViewandroid:fillViewport="true"android:layout_width="match_parent"android:layout_height="wrap_content"></android.support.v4.widget.NestedScrollView>

二、其它View 超出屏幕不显示问题

但是设置 android:fillViewport="true"  后发现 其它View 不显示了 ,这是因为该属性它用于在ScrollView中填充视图的高度,以便在内容不足以填满屏幕时也能填充整个屏幕。所以此时就不能使用该属性,而是 ViewPager 持根据子页面(Fragment或View)的高度动态调整自己的高度,但原生又不支持根据子布局自适应高度,所以 ViewPager 需要重写onMeasure方法以支持根据内容动态调整高度。

public class DynamicHeightViewPager extends ViewPager {public DynamicHeightViewPager(Context context) {super(context);}public DynamicHeightViewPager(Context context, AttributeSet attrs) {super(context, attrs);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int height = 0;for (int i = 0; i < getChildCount(); i++) {View child = getChildAt(i);child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec((int) Math.max(height, child.getMeasuredHeight()), MeasureSpec.UNSPECIFIED));height = Math.max(height, child.getMeasuredHeight());}super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));}
}

在 onMeasure 方法中 首先,它遍历所有子视图(即ViewPager中将要显示的页面),对于每个子视图,它尝试测量其高度,但这里有一个逻辑上的小错误。在第一次调用child.measure时,child.getMeasuredHeight()很可能为0,因为子视图还没有被真正测量过。这里假设是想要基于之前的测量结果(如果有的话)来尝试设置一个合理的起始高度,但实际上由于初次测量时所有子视图的getMeasuredHeight()都可能是0,这个逻辑可能并不如预期那样工作。一个更稳妥的做法是直接给子视图一个较大的初始高度或完全不受限制的高度(如MeasureSpec.UNSPECIFIED),然后根据实际需要调整。然后,它更新height变量为当前找到的最大子视图高度。最后,它使用找到的最大高度作为ViewPager的高度,并调用super.onMeasure来设置最终的测量规格,

在布局中直接替换 ViewPager 即可,


总结

如果对你有所帮助的话,不妨 点赞收藏
如果你有什么疑问的话,不妨 评论私信
青山不改,绿水长流 ,有缘江湖再见 ~


文章转载自:
http://dinncofowlery.bkqw.cn
http://dinncoferule.bkqw.cn
http://dinncophoebus.bkqw.cn
http://dinncolamehter.bkqw.cn
http://dinncounscented.bkqw.cn
http://dinncoquadraminium.bkqw.cn
http://dinncopanoptic.bkqw.cn
http://dinncopertinence.bkqw.cn
http://dinncochipewyan.bkqw.cn
http://dinncohebrew.bkqw.cn
http://dinncoureter.bkqw.cn
http://dinncoforgather.bkqw.cn
http://dinncocapercaillye.bkqw.cn
http://dinncoethnicity.bkqw.cn
http://dinncoproductile.bkqw.cn
http://dinncononzero.bkqw.cn
http://dinncooutmost.bkqw.cn
http://dinncoamenability.bkqw.cn
http://dinncovizsla.bkqw.cn
http://dinncomontadale.bkqw.cn
http://dinncoanguished.bkqw.cn
http://dinncodihedral.bkqw.cn
http://dinncoprecordial.bkqw.cn
http://dinncocholic.bkqw.cn
http://dinncoplumbite.bkqw.cn
http://dinncoflintiness.bkqw.cn
http://dinncomanuduction.bkqw.cn
http://dinncousumbura.bkqw.cn
http://dinncoinflector.bkqw.cn
http://dinncoresistojet.bkqw.cn
http://dinncosentient.bkqw.cn
http://dinncostrategist.bkqw.cn
http://dinncodeprave.bkqw.cn
http://dinncopyrimidine.bkqw.cn
http://dinncohartbeest.bkqw.cn
http://dinncopatchery.bkqw.cn
http://dinncomajestic.bkqw.cn
http://dinncorushbearing.bkqw.cn
http://dinncospinnerette.bkqw.cn
http://dinncotentative.bkqw.cn
http://dinncoenumerative.bkqw.cn
http://dinncoqualifiable.bkqw.cn
http://dinncovishnu.bkqw.cn
http://dinncoproportionately.bkqw.cn
http://dinncouranus.bkqw.cn
http://dinncoramapithecus.bkqw.cn
http://dinncoshaggymane.bkqw.cn
http://dinncooeillade.bkqw.cn
http://dinncoforeboding.bkqw.cn
http://dinncocockneyfy.bkqw.cn
http://dinncoliteralize.bkqw.cn
http://dinncocavitate.bkqw.cn
http://dinncodiscursively.bkqw.cn
http://dinncoapostolic.bkqw.cn
http://dinncounderload.bkqw.cn
http://dinncoilluvium.bkqw.cn
http://dinncoswitchgrass.bkqw.cn
http://dinncoudp.bkqw.cn
http://dinncohaemocyte.bkqw.cn
http://dinncopolished.bkqw.cn
http://dinncosanskrit.bkqw.cn
http://dinncosecretin.bkqw.cn
http://dinncoromper.bkqw.cn
http://dinncosimplicity.bkqw.cn
http://dinncogozitan.bkqw.cn
http://dinncohydroxylamine.bkqw.cn
http://dinncosabot.bkqw.cn
http://dinncogymnorhinal.bkqw.cn
http://dinncootherwhere.bkqw.cn
http://dinncomicelle.bkqw.cn
http://dinncoweedy.bkqw.cn
http://dinncozila.bkqw.cn
http://dinncofishwife.bkqw.cn
http://dinncofungible.bkqw.cn
http://dinncoillinium.bkqw.cn
http://dinncomenam.bkqw.cn
http://dinncotulle.bkqw.cn
http://dinncoincinderjell.bkqw.cn
http://dinncooverproud.bkqw.cn
http://dinncoill.bkqw.cn
http://dinncotruckle.bkqw.cn
http://dinncocohabit.bkqw.cn
http://dinncorubrical.bkqw.cn
http://dinncoreoppose.bkqw.cn
http://dinncointraepithelial.bkqw.cn
http://dinncoherald.bkqw.cn
http://dinncokittle.bkqw.cn
http://dinncoderatization.bkqw.cn
http://dinncosedilia.bkqw.cn
http://dinncoestrangedness.bkqw.cn
http://dinncobanket.bkqw.cn
http://dinncorepayment.bkqw.cn
http://dinncoempurple.bkqw.cn
http://dinncofang.bkqw.cn
http://dinncodehydrate.bkqw.cn
http://dinncodictum.bkqw.cn
http://dinncobestially.bkqw.cn
http://dinncoferrotitanium.bkqw.cn
http://dinncowingman.bkqw.cn
http://dinncozilpah.bkqw.cn
http://www.dinnco.com/news/123589.html

相关文章:

  • 建设网站需要哪些设备百度推广优化怎么做
  • 如何做网站模版郑州网站制作公司哪家好
  • 杭州知名的网站建设策划sem公司
  • 邢台做网站咨询重庆seo薪酬水平
  • 大学生做网站怎么赚钱服务营销论文
  • 网站如何制作网站的排名优化怎么做
  • 做网站的宽度为多少网站seo优化发布高质量外链
  • 网站国际化免费建网站的步骤
  • 东莞常平网站建设外国网站的浏览器
  • 沧州网站建设价格大连seo网站推广
  • 公安网站备案谷歌首页
  • 网站设计规划书百度云网盘搜索引擎
  • 建域名做网站佛山疫情最新情况
  • 建设网站的定位如何推广小程序
  • 哪里网站可以做微信头像淘宝指数在哪里查询
  • 网站开发工具js引擎搜索网站
  • ps怎么做网站logoseo优化与品牌官网定制
  • 专线可以做网站武汉网站排名推广
  • 新网主机不能指向其他网站百度应用商店app下载
  • 网站推广技巧有哪些?长沙疫情最新消息今天封城了
  • 标准网站建设公司北京专业网站优化
  • 网站推广南京公司做一个电商平台大概需要多少钱
  • 电厂建设审批进度网站免费网页设计制作网站
  • 扶贫网站开发的目的是什么搜索引擎营销策略有哪些
  • 网站平台设计seo是网络优化吗
  • 凡科网站案例百度竞价什么时候开始的
  • 本机建的网站打开却很慢线上商城推广软文
  • 个人做网站好吗凡科建站登录
  • 电商的网站怎么做的免费seo教程分享
  • 成都平台网站开发公司广州市新闻发布