Android xamarin表单中的自动宽度或高度
正如我们在android中所知道的,我们可以使用Android xamarin表单中的自动宽度或高度,android,xamarin,xamarin.android,xamarin.forms,Android,Xamarin,Xamarin.android,Xamarin.forms,正如我们在android中所知道的,我们可以使用 android:width='wrap_content' android:height='match_parent' 设置视图的宽度或高度。 但是,在xamarin形式中,我们不能使用它 那么,如何为xamarin窗体组件设置动态宽度或高度呢像android中的match_parent或wrap_content一样,查看HorizontalOptions和VerticalOptions下的选项。听起来像是你要找的是FillAndExpand。在
android:width='wrap_content'
android:height='match_parent'
设置视图的宽度或高度。但是,在xamarin形式中,我们不能使用它
那么,如何为xamarin窗体组件设置动态宽度或高度呢
像android中的
match_parent
或wrap_content
一样,查看HorizontalOptions和VerticalOptions下的选项。听起来像是你要找的是FillAndExpand。在Xamarin表单中,你可以使用LayoutOptions执行相同的操作
假设您有一个按钮,当其父按钮增长时,您希望该按钮水平(宽度)增长,您可以使用:
var button4 = new Button {Text = "Click Me!", HorizontalOptions=LayoutOptions.FillAndExpand, VerticalOptions=LayoutOptions.Center};
LayoutOptions.FillAndExpand意味着它将占用其父视图中所有可用的空间(有些例外)
在XAML中,这将是:
<Button Text="Click Me!"
HorizontalOptions="FillAndExpand"
VerticalOptions="Center" />
建议您查看Xamarin表单的列表。hi@apineda感谢您的回答,我使用了您的解决方案并在stacklayout中工作,但当我使用relativelayout时失败,意味着按钮不想居中,这是因为在Android(java)中使用relativelayout时,定位方法不同。Xamarin.Forms中的RelativeLayout指南可在此处查看: