2

Hi i'm trying to place 2 image in xamarin forms using stackLayout.But it adds some space at the top of the form.I Used Blank Project. my code is

<StackLayout>

    <Image Source="review.jpg"
               BackgroundColor="Transparent"
        WidthRequest="300"
        HeightRequest="100"
        VerticalOptions="Start" HorizontalOptions="FillAndExpand"
        FlexLayout.Grow="1">
        <Image.GestureRecognizers>
            <TapGestureRecognizer Tapped="Navigate_review"/>
        </Image.GestureRecognizers>
    </Image>

    <Image Source="upload.jpg"
               BackgroundColor="Transparent"
        WidthRequest="320"
        HeightRequest="100"
        VerticalOptions="Start" HorizontalOptions="FillAndExpand"
        FlexLayout.Grow="1">
        <Image.GestureRecognizers>
            <TapGestureRecognizer Tapped="Navigate_upload"/>
        </Image.GestureRecognizers>
    </Image>
</StackLayout>

i am getting this output:

Output Image 1
Output Image 2

It adds some extra space at the top of the page. how to set the layout to remove this space?

Anu Priya
  • 87
  • 1
  • 2
  • 10

5 Answers5

1

The code you post does not have any issue. I reckon your app is created with Tabbed template. If that is the case, the empty space at the top is actually the tab. As shown in this image. tabbed

If you create a Blank project (not Tabbed nor MasterDetails), it will not have the empty spaces at the top. As shown in this image. enter image description here

jedipi
  • 155
  • 4
1

You can use the Margin attribute to remove the excess space on top, bottom, right or left. Let's assume, if we using a table view and it produces the 20 pixel excess space on top of the display. So we can reduce that excess space by using

<TableView Margin="0,-20,0,0" >
<TableVie/>

-20 using for reduce the excess 20pix

Adithya
  • 265
  • 4
  • 9
0

StackLayout and Grid have default spacing of 6. On StackLayout you can set Spacing. For more details, you can refer to this Document

Try this snippet:

 <StackLayout
        Spacing="0">
        <Image
            Source="hintsicon"
            BackgroundColor="Transparent"
            WidthRequest="300"
            HeightRequest="100"
            Aspect="Fill"
            VerticalOptions="Start"
            HorizontalOptions="FillAndExpand">
            <Image.GestureRecognizers>
                <TapGestureRecognizer
                    Tapped="Navigate_review" />
            </Image.GestureRecognizers>
        </Image>
        <Image
            Source="hintsicon"
            BackgroundColor="Transparent"
            WidthRequest="320"
            HeightRequest="100"
            Aspect="Fill"
            VerticalOptions="Start"
            HorizontalOptions="FillAndExpand">
            <Image.GestureRecognizers>
                <TapGestureRecognizer
                    Tapped="Navigate_upload" />
            </Image.GestureRecognizers>
        </Image>
    </StackLayout>
Jaymin
  • 2,879
  • 3
  • 19
  • 35
0

I think the problem is you are testing on emulators.Real devices will not show this issue I hope.

Anand
  • 1,866
  • 3
  • 26
  • 49
  • I don't want to hide the action bar.just want to hide blue color which is present after the action bar and before the button.I added Aspect like your code but still same i'm getting – Anu Priya Mar 19 '19 at 06:56
  • Okey as I said above in comment section, Test it on real devices, Problem will be solved i guess – Anand Mar 19 '19 at 06:57
0

I think you are using like below in your App.xaml.cs page:

MainPage = new NavigationPage(new MainPage());
Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79
Sumel
  • 1
  • 1