android–PercentRelativeLayout 23.2.1里面的ScrollView不正确的零高度

android–PercentRelativeLayout 23.2.1里面的ScrollView不正确的零高度,第1张

概述我有一个布局,其中包含一个带有LinearLayout及其子项的ScrollView:一个PercentRelativeLayout23.2.1,另一个下面的LinearLayout和另一个PercentRelativeLayout.在LinearLayout中间我有一个RecyclerView(LinearLayoutManager,vertical).您可以在下面看到一个示例.在运行时,当我用Re

我有一个布局,其中包含一个带有linearLayout及其子项的ScrollVIEw:一个PercentrelativeLayout 23.2.1,另一个下面的linearLayout和另一个PercentrelativeLayout.在linearLayout中间我有一个RecyclerVIEw(linearlayoutmanager,vertical).您可以在下面看到一个示例.

在运行时,当我用RecycleVIEw填充数据时,它的大小会增加,因为我从一个空数据开始.一旦其高度变化超过屏幕尺寸,汽车的上方图像(ID = car),其百分比值作为其高度,将完全从屏幕上消失.当我上下滚动此屏幕时,我到达顶部和底部边缘并且看不到图像.

我在此布局中的另一个位置也有百分比值,它们定义margintop.这些边缘也消失了.与宽度相关的百分比值工作正常. java代码不包含图像的可见性更改,也不会调整边距.

我目前还不确定这个问题是否与支持库的特定版本有关,我在发布此库的同时构建了这个屏幕.另外,我没有在Marshmallow上看到这个问题,只在Lollipop及以下.我将不胜感激如何解决这个问题.

<!-- a container for all vIEws that should scroll --><linearLayout    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:orIEntation="vertical">    <!-- the first block of vIEws - they need percents -->    <androID.support.percent.PercentrelativeLayout        androID:ID="@+ID/carHolder"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content">        <ImageVIEw            androID:ID="@+ID/car"            androID:layout_wIDth="wrap_content"            androID:layout_alignParenttop="true"            androID:layout_centerHorizontal="true"            androID:src="@drawable/car"            app:layout_heightPercenet="25%"/>        <ImageVIEw            androID:ID="@+ID/slIDerBg"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_below="@ID/car"            androID:layout_centerHorizontal="true"            androID:src="@drawable/slIDer_bg"/>    </androID.support.percent.PercentrelativeLayout>    <!-- a mIDdle block of vIEws, they don't need percents -->     <linearLayout            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:orIEntation="vertical">         <androID.support.v7.Widget.RecyclerVIEw                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"/>    </linearLayout>    <!-- another block of vIEws, they need percents -->    <androID.support.percent.PercentrelativeLayout            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content">        <!-- some other vIEws -->     </androID.support.percent.PercentrelativeLayout></linearLayout>

UPDATE

我在支持库23.3.0中也看到了这个问题,不仅在我填充RecyclerVIEw时,而且每次ScrollVIEw都超过了屏幕高度.

解决方法:

不幸的是,百分比布局在M之前不适用于ScrollVIEw.原因在于它们取决于测量步骤中提供的大小提示.在M之前,大多数布局在发送未指定的测量规范时会提供大小提示0.

您可以尝试通过创建自己的ScrollVIEw子类并重写measureChild和measureChilDWithmargins(幸运的是两者都受到保护)来修复它,以提供大小提示.
source- plus.Google.com

您可以使用此CustomScrollVIEw使percentrelativeLayout正常工作

public class CustomScrollVIEw extends ScrollVIEw {public CustomScrollVIEw(Context context) {    super(context);}public CustomScrollVIEw(Context context, AttributeSet attrs) {    super(context, attrs);}public CustomScrollVIEw(Context context, AttributeSet attrs, int defStyleAttr) {    super(context, attrs, defStyleAttr);}@TargetAPI(Build.VERSION_CODES.LolliPOP)public CustomScrollVIEw(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {    super(context, attrs, defStyleAttr, defStyleRes);}@OverrIDeprotected voID onMeasure(int wIDthMeasureSpec, int heightmeasureSpec) {    super.onMeasure(wIDthMeasureSpec, heightmeasureSpec);    int size = 0;    int wIDth = getMeasureDWIDth();    int height = getMeasuredHeight();    if (wIDth > height) {        size = height;    } else {        size = wIDth;    }    setMeasuredDimension(size, size);}}

来源是PercentRelativeLayout inside ScrollView

总结

以上是内存溢出为你收集整理的android – PercentRelativeLayout 23.2.1里面的ScrollView不正确的零高度全部内容,希望文章能够帮你解决android – PercentRelativeLayout 23.2.1里面的ScrollView不正确的零高度所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1119422.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存