调整StackLayout元素的高度
问题描述:
我对Xamarin Forms真的很陌生,我刚刚被赋予调整此应用程序的Android版本UI的任务。在Android手机上,用户界面看起来很好,但在平板电脑上它有点小。所以我开发了一个新的页面,当设备是平板电脑时,但我似乎无法调整StackLayout元素的高度。这里是代码:调整StackLayout元素的高度
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout VerticalOptions="Fill" Spacing="0" Padding="0" Margin="0">
<StackLayout VerticalOptions="Fill" HeightRequest="60" Padding="2" Orientation="Horizontal">
<Label VerticalOptions="Center" FontSize="19" Margin="14,0,0,0" Text="{Binding Name}" TextColor="White" ></Label>
<Image VerticalOptions="Center" HorizontalOptions="EndAndExpand" HeightRequest="50" WidthRequest="30" Source="imgArrow.png"></Image>
</StackLayout>
<BoxView Margin="0,2,0,0" HeightRequest="0.5" BackgroundColor="White" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
知道我在HeightRequest字段中放置了什么值,它看起来总是一样的。我相信我在这里错过了一些完全基础的东西。屏幕https://imgur.com/MAHgOgr的外观如下。我只是希望它占用更多的空间,这将涉及增加字体大小,但是当我这样做时,它看起来很糟糕。 pic with font size 40。任何帮助,我可以得到非常感谢。谢谢!
答
您是否尝试将listview的“HasUnevenRows”属性设置为true?
我认为这将解决您的问题与字体大小
答
- 检测,如果是平板电脑/手机,设置正确的高度变量,你会用
- ,因为你是在一个DataTemplate绑定HeightRequest的变量你已经设定好了。
对于数据模板之外的简单情况,您可以将x:name赋予元素,然后在构造函数中为这些名称设置widthrequests。
非常感谢。有用! – Ryan