TextWrapped Label 打破 StackLayout 中的布局选项 FillAndExpand
TextWrapped Label breaks Layout Option FillAndExpand in StackLayout
我有一个带有嵌套 StackLayout
s 的单元格视图,如果文本很长,将换行一个标签,这是所需的行为。但是,换行打破了 LayoutOptions
设置为(基本上)所有父视图,导致右侧出现灰色间隙。
<StackLayout Orientation="Horizontal" BackgroundColor="Gray" Margin="0,30,0,0">
<BoxView
HorizontalOptions="Start"
BackgroundColor="#EEBB00"
WidthRequest="100"
/>
<StackLayout
BackgroundColor="#CC4400"
HorizontalOptions="FillAndExpand"
>
<BoxView
BackgroundColor="Green"
HeightRequest="10"
HorizontalOptions="FillAndExpand"
/>
<Label
FontSize="16"
HorizontalOptions="FillAndExpand"
Text="Name that is toolongandwillbewrapped"
/>
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
BackgroundColor="Blue"
>
<Label
FontSize="13"
Text="Left"
TextColor="White"
HorizontalOptions="StartAndExpand"
VerticalTextAlignment="End"
/>
<Label
FontSize="13"
Text="Right"
TextColor="White"
HorizontalOptions="EndAndExpand"
VerticalTextAlignment="End"
/>
</StackLayout>
</StackLayout>
</StackLayout>
生成的视图是:
所以我可以说出为什么会这样,但是,我当然不喜欢它。预期的行为是右侧堆栈布局一直向右扩展。我试过各种方法来规避这一点,如果我成功了,我就不会来这里了。有人有想法吗?
不幸的是,这是 Xamarin.Forms 中的错误(可能仅 iOS)。
这种情况下的解决方法是使用 Grid
而不是 StackLayout
:http://forums.xamarin.com/discussion/comment/152969/#Comment_152969
我有一个带有嵌套 StackLayout
s 的单元格视图,如果文本很长,将换行一个标签,这是所需的行为。但是,换行打破了 LayoutOptions
设置为(基本上)所有父视图,导致右侧出现灰色间隙。
<StackLayout Orientation="Horizontal" BackgroundColor="Gray" Margin="0,30,0,0">
<BoxView
HorizontalOptions="Start"
BackgroundColor="#EEBB00"
WidthRequest="100"
/>
<StackLayout
BackgroundColor="#CC4400"
HorizontalOptions="FillAndExpand"
>
<BoxView
BackgroundColor="Green"
HeightRequest="10"
HorizontalOptions="FillAndExpand"
/>
<Label
FontSize="16"
HorizontalOptions="FillAndExpand"
Text="Name that is toolongandwillbewrapped"
/>
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
BackgroundColor="Blue"
>
<Label
FontSize="13"
Text="Left"
TextColor="White"
HorizontalOptions="StartAndExpand"
VerticalTextAlignment="End"
/>
<Label
FontSize="13"
Text="Right"
TextColor="White"
HorizontalOptions="EndAndExpand"
VerticalTextAlignment="End"
/>
</StackLayout>
</StackLayout>
</StackLayout>
生成的视图是:
所以我可以说出为什么会这样,但是,我当然不喜欢它。预期的行为是右侧堆栈布局一直向右扩展。我试过各种方法来规避这一点,如果我成功了,我就不会来这里了。有人有想法吗?
不幸的是,这是 Xamarin.Forms 中的错误(可能仅 iOS)。
这种情况下的解决方法是使用 Grid
而不是 StackLayout
:http://forums.xamarin.com/discussion/comment/152969/#Comment_152969