我们知道在android中我们可以使用
android:width='wrap_content'
android:height='match_parent'
设置 View 的宽度或高度。
但是,在 xamarin 形式中我们不能使用它。
那么如何为我的 xamarin 表单组件设置动态宽度或高度?
比如android中的match_parent
或者wrap_content
最佳答案
在 Xamarin.Forms 中,您可以使用 LayoutOptions 执行相同的操作。
假设您有一个 Button,您希望它随着父级的增长而水平增长(宽度),您可以使用:
var button4 = new Button {Text = "Click Me!", HorizontalOptions=LayoutOptions.FillAndExpand, VerticalOptions=LayoutOptions.Center};
LayoutOptions.FillAndExpand 表示它将占据其父 View 中所有可能的可用空间(有一些异常(exception))。
在 XAML 中是:
<Button Text="Click Me!"
HorizontalOptions="FillAndExpand"
VerticalOptions="Center" />
建议你看Getting Started Xamarin 表单。
关于android - xamarin 表单中的自动宽度或高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42217812/