android – RelativeLayout在StackLayout宽度计算

android – RelativeLayout在StackLayout宽度计算,第1张

概述我在StackLayout嵌套的RelativeLayouts有一个奇怪的问题,似乎StackLayout计算其元素的宽度应该是使用RelativeLayout宽度,然后RelativeLayout再次重新计算它.这导致子控件是相对宽度的平方,但是下列控件被放置在相对宽度. 这是一个bug还是我做错了? 例 <?xml version="1.0" encoding="utf-8" ?><Cont 我在StackLayout嵌套的relativeLayouts有一个奇怪的问题,似乎StackLayout计算其元素的宽度应该是使用relativeLayout宽度,然后relativeLayout再次重新计算它.这导致子控件是相对宽度的平方,但是下列控件被放置在相对宽度.

这是一个BUG还是我做错了?

<?xml version="1.0" enCoding="utf-8" ?><ContentPage x:Class="MyClass"             xmlns="http://xamarin.com/schemas/2014/forms"             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"             >  <StackLayout OrIEntation="Horizontal" Backgroundcolor="Blue">    <relativeLayout>      <ContentVIEw Backgroundcolor="Red"          relativeLayout.XConstraint=                "{ConstraintExpression Type=relativetoparent,Property=WIDth,Factor=0}"          relativeLayout.WIDthConstraint=                "{ConstraintExpression Type=relativetoparent,Factor=0.707106}"          relativeLayout.YConstraint=                  "{ConstraintExpression Type=relativetoparent,Property=Height,Factor=0}"          relativeLayout.HeightConstraint=                "{ConstraintExpression Type=relativetoparent,Factor=1}">      </ContentVIEw>    </relativeLayout>    <relativeLayout>      <ContentVIEw Backgroundcolor="Green"          relativeLayout.XConstraint=                "{ConstraintExpression Type=relativetoparent,Factor=0.5}"          relativeLayout.YConstraint=                  "{ConstraintExpression Type=relativetoparent,Factor=1}">      </ContentVIEw>    </relativeLayout>  </StackLayout></ContentPage>

解决方法 两个relativeLayout元素可能是一个混乱的因素,并且每个被指定为相对于父StackLayout处于X位置0的事实,这似乎是一个冲突.

从注释中可以看出,如果每个relativeLayout预期为父StackLayout的宽度的一半,则可以通过删除relativeLayout元素之一来简化布局.

然后可以将子条的指定宽度除以2,使得每个的宽度相对于父StackLayout是相同的,并且相对于父对象设置的X位置也是水平位置.

这是我想出来的:

<?xml version="1.0" enCoding="utf-8" ?><ContentPage x:Class="App1.HomePage"         xmlns="http://xamarin.com/schemas/2014/forms"         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"><StackLayout OrIEntation="Horizontal" Backgroundcolor="Blue">  <relativeLayout>    <ContentVIEw Backgroundcolor="Red"        relativeLayout.XConstraint=          "{ConstraintExpression Type=relativetoparent,Factor=0}"        relativeLayout.WIDthConstraint=          "{ConstraintExpression Type=relativetoparent,Factor=0.35}"        relativeLayout.YConstraint=          "{ConstraintExpression Type=relativetoparent,Factor=0}"        relativeLayout.HeightConstraint=          "{ConstraintExpression Type=relativetoparent,Factor=1}">    </ContentVIEw><!--</relativeLayout><relativeLayout>-->    <ContentVIEw Backgroundcolor="Green"        relativeLayout.XConstraint=          "{ConstraintExpression Type=relativetoparent,Factor=0.5}"        relativeLayout.WIDthConstraint=          "{ConstraintExpression Type=relativetoparent,Factor=0.25}"        relativeLayout.YConstraint=          "{ConstraintExpression Type=relativetoparent,Factor=1}">      </ContentVIEw>    </relativeLayout>  </StackLayout></ContentPage>

这会产生更接近预期的东西吗?

总结

以上是内存溢出为你收集整理的android – RelativeLayout在StackLayout宽度计算全部内容,希望文章能够帮你解决android – RelativeLayout在StackLayout宽度计算所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存