小编Uka*_*pts的帖子

有没有办法制作具有固定纵横比的 NativeScript GridLayout?

首先,如果我不遵守任何 SO 规则,我想道歉,因为这是我的第一个问题。

我想要完成的是在我的页面中有一个方形的gridLayout。该行为应该等同于拥有一个带有stretch="aspectFit"的元素。

如果建议的解决方案可以让我强制执行任何给定的纵横比,而不仅仅是一个正方形,那将是一个不错的加分,因为它可以让我在未来解决多种情况。或者如果它可以应用于任何 Layout 元素,那也很好。

该解决方案可以随心所欲,并且 GridLayout 可以以您需要的任何方式嵌套以完成此任务。

我已经尝试过像这样破解它:

 <GridLayout rows="*,auto,*" columns="*,auto,*" backgroundColor="green">
  <Image row="1" col="1" src="~/Images/1px-black.png" stretch="aspectFit" width="100%"></Image>
  <StackLayout row="1" col="1" orientation="vertical" backgroundColor="lightgray">
    <Label text="Label 1" width="100%" height="25%" backgroundColor="red"></Label>
    <Label text="Label 2" width="100%" height="25%" backgroundColor="green"></Label>
    <Label text="Label 3" width="100%" height="25%" backgroundColor="blue"></Label>
    <Label text="Label 4" width="100%" height="25%" backgroundColor="yellow"></Label>
  </StackLayout>
</GridLayout>
Run Code Online (Sandbox Code Playgroud)

视觉上它似乎有效,但 GridLayout 的内容没有适当地填充它

PS:我刚刚注意到在我选择的示例中,我试图制作方形的布局元素是嵌套的 StackLayout,但它的想法是相同的。我需要一种方法来使嵌套布局元素平方。

aspect-ratio grid-layout aspect-fit nativescript

5
推荐指数
1
解决办法
6680
查看次数