有时我在Android中的标签或摘录中的文字会在标签结束之前换行。它不会每次都发生,但是当它发生时,文本最初会正确显示,然后很快就会被错误地重新渲染。这只发生在视图位于网格中时,但我无法确定原因是什么。使用“显示布局边界”选项,我可以看到标签的宽度是正确的并且不会改变,它只是不正确的自动换行。
ContentView子类构造函数中的相关代码:
Grid _contentGrid = new Grid()
{
RowDefinitions = new RowDefinitionCollection()
{
new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
},
ColumnDefinitions = new ColumnDefinitionCollection()
{
new ColumnDefinition() { Width = 48 },
new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) },
},
BackgroundColor = Color.Transparent,
Padding = new Thickness(16, 16, 16, 16),
ColumnSpacing = 16,
RowSpacing = 8,
HorizontalOptions = LayoutOptions.FillAndExpand
};
Label _questionLabel = new Label()
{
Text = "Do you want to update the instrument setup?",
TextColor = Color.FromHex(Colours.TextGrey),
HorizontalOptions = LayoutOptions.FillAndExpand,
XAlign = TextAlignment.Start,
WidthRequest = 344
};
_contentGrid.Children.Add(_questionLabel, 0, 2, 3, 4);
DialogView dialogView = new DialogView()
{
TopView = TitleLabel,
MiddleView = _contentGrid,
BottomView = ButtonGrid,
TopColour = Color.FromHex(Colours.Blue),
MiddleColour = Color.White,
BottomColour = Color.White,
MiddleHeight = 150,
};
Grid Holder = new Grid()
{
ColumnDefinitions = new ColumnDefinitionCollection()
{
new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) },
new ColumnDefinition() { Width = 368 },
new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) },
},
RowDefinitions = new RowDefinitionCollection()
{
new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) },
new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) },
},
BackgroundColor = Color.FromHex("b0000000")
};
Holder.Children.Add(dialogView, 1, 1);
this.Content = Holder;
_questionLabel文本仅显示“你想要”