如何使按鈕出現在一行中
。這是我的代碼。
這是我的代碼
這是我的代碼。
namespace RowCounter.Forms
{
public partial class MainPage : ContentPage >。
{
public int Number = 1;
public MainPage()
{
InitializeComponent()。
}
public object Children { get; private set; }
void OnButtonClicked(object sender, EventArgs e).
{
Button button = new Button
{
Text = "NAME PRODJECT" " Number,
TextColor= Color.Red,
WidthRequest =450,
HorizontalOptions = LayoutOptions.Start
};
Button button2 = new Button
{
Text = "X"/span>,
WidthRequest = 40,
HorizontalOptions = LayoutOptions.End
};
MainStackLayout.Children.Add(button2)。
MainStackLayout.Children.Add(button)。
Number ;
}
}
}
而我的xaml代碼
<StackLayout x。 Name ="MainStackLayout" BackgroundColor="#9370db">
<Button Text="СОЗДАТЬ ПРОЕКТ"/span>
FontAttributes="Bold"。
FontSize="25"。
WidthRequest="250"。
HeightRequest="80"/span>
Clicked="OnButtonClicked"。
TextColor="#ff000000"/span>
BackgroundColor="#4b0082"/>
</StackLayout>/span>
請幫助我
uj5u.com熱心網友回復:
使用Grid而不是Stacklayout.
。從檔案中:
第二個選項,盡管不推薦,將是嵌套Stacklayouts:一個Stacklayout的Stacklayouts由兩個按鈕組成,方向設定為水平。這是不好的做法,對性能也不好,因為
uj5u.com熱心網友回復:
如果你有幾個按鈕,網格就很好。如果按鈕的數量超過5個,按鈕在手機APP中可能會被過度放大,因為手機的尺寸是有限的。
可選的是使用FlexLayout(見:https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.flexlayout?view=xamarin-forms)。. 你可以水平地布局按鈕,如果空間不夠,可以自動分成多行。
例子:
FlexLayout flex = new FlexLayout()。
flex.HorizontalOptions = LayoutOptions.Fill;
flex.VerticalOptions = LayoutOptions.StartAndExpand;
flex.Direction = FlexDirection.Row。
flex.Wrap = FlexWrap.Wrap。
/>添加按鈕
flex.Children.Add(button1)。
flex.Children.Add(button2);
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/329859.html
標籤:


