java文本区水平对齐方式,如何将文本居中在水平StackLayout中?

当您想要将View放在特定位置时,StackLayout并不是很好 . 当你有很多观点时,这是很好的,你希望它们都以合理的方式出现 .

如果你想要像素完美的东西,有两个很棒的布局:

AbsoluteLayout

RelativeLayout

对于你的具体问题,我会说使用AbsoluteLayout,因为用它来集中Label是非常容易的 . 对于此解决方案,我将Nav Bar的StackLayout更改为AbsoluteLayout,并在代码后面添加了布局参数 .

XAML:

背后的代码:

public MyPage ()

{

InitializeComponent ();

NavBarLayout.Children.Add (

btnBack,

// Adds the Button on the top left corner, with 10% of the navbar's width and 100% height

new Rectangle(0, 0, 0.1, 1),

// The proportional flags tell the layout to scale the value using [0, 1] -> [0%, 100%]

AbsoluteLayoutFlags.HeightProportional | AbsoluteLayoutFlags.WidthProportional

);

NavBarLayout.Children.Add(

labelTitle,

// Using 0.5 will center it and the layout takes the size of the element into account

// 0.5 will center, 1 will right align

// Adds in the center, with 90% of the navbar's width and 100% of height

new Rectangle(0.5, 0.5, 0.9, 1),

AbsoluteLayoutFlags.All

);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值