Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Label text into rounded boxview

I want to add text over BoxView component through AbsoluteLayout in codebehind.
Something like this:

enter image description here

How can I do it?

Here is my code, where I put AbsoluteLayout into StackLayout at the end:

 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;
    }

So, my concern is that this l component is sticked to stacklayout and not for BoxView.

Maybe I should try with RelativeLayout?

Do you know some component on git? like XLabs?

Thanks.

like image 844
Stefan0309 Avatar asked Feb 13 '17 14:02

Stefan0309


2 Answers

You can try Frame instead of Absolute Layout like this

<Frame BackgroundColor="#13CF13" Padding="5" HorizontalOptions="Center" WidthRequest="80" HeightRequest="20" CornerRadius="40">
        <Label WidthRequest="40" Text="Backlog" HorizontalTextAlignment="Center"></Label>
    </Frame>

Gives you this result:

enter image description here

like image 82
Favas Kv Avatar answered Nov 09 '22 09:11

Favas Kv


This is a very old question but I just achieved this as following.

In 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>

And this is what it loos like in the app

enter image description here

like image 44
Salman Avatar answered Nov 09 '22 10:11

Salman