Ste*_*309 7 visual-studio xamarin xamarin.forms
我想在代码隐藏中通过BoxView组件添加文本AbsoluteLayout。
像这样的东西:
我该怎么做?
这里是我的代码,在那里我把AbsoluteLayout到StackLayout结尾:
public TestPageBoxView()
{
StackLayout sl = new StackLayout();
AbsoluteLayout al = new AbsoluteLayout();
BoxView bv = new BoxView { BackgroundColor = Color.Green };
Label l = new Label { Text = "Some text with \n breaks" };
AbsoluteLayout.SetLayoutBounds(l, new Rectangle(0, 0,1,1));
AbsoluteLayout.SetLayoutFlags(l, AbsoluteLayoutFlags.All);
sl.Children.Add(bv);
sl.Children.Add(al);
Content = sl;
}
Run Code Online (Sandbox Code Playgroud)
所以,我担心的是这个l组件被坚持到 stacklayout 而不是 BoxView。
也许我应该试试RelativeLayout?
你知道 git 上的一些组件吗?喜欢 XLabs?
谢谢。
您可以像这样尝试使用 Frame 而不是 Absolute Layout
<Frame BackgroundColor="#13CF13" Padding="5" HorizontalOptions="Center" WidthRequest="80" HeightRequest="20" CornerRadius="40">
<Label WidthRequest="40" Text="Backlog" HorizontalTextAlignment="Center"></Label>
</Frame>
Run Code Online (Sandbox Code Playgroud)
给你这个结果:
这是一个非常古老的问题,但我刚刚实现了这一点,如下所示。
在 XAML 中
<StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<BoxView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HeightRequest="2" />
<Label Text="{Binding Caption}" Grid.Row="0" FontAttributes="Bold" BackgroundColor="Silver" FontSize="Large"/>
</Grid>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
这就是应用程序中的样子
| 归档时间: |
|
| 查看次数: |
11110 次 |
| 最近记录: |