xamarin.forms - How to properly use an AbsoluteLayout inside a StackLayout inside a ScrollView in Xamarin? -


ok, give up. 3 days spent trying accomplish simple thing.

here scenario (not on same xaml file):

<tabbedpage>   <navigationpage>     <contentpage/>     <contentpage/>     <carouselpage>       <carouselcontentpage> 

this carouselcontentpage:

<contentpage xmlns="http://xamarin.com/schemas/2014/forms"              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"              x:class="myapp.layouts.pointinfodatatemplate"              >   <contentpage.content>       <scrollview orientation="vertical" backgroundcolor="navy" verticaloptions="fill">       <stacklayout x:name="mystacklayout" horizontaloptions="startandexpand" verticaloptions="start" backgroundcolor="gray">         <label x:name="namelabel" fontsize="medium" horizontaloptions="center"/>         <label x:name="desclabel" fontsize="medium" horizontaloptions="center" />         <absolutelayout x:name="imgscontainer" verticaloptions="start" backgroundcolor="green">           <image x:name="backimg" aspect="aspectfit" verticaloptions="start"/>           <image x:name="midimg" aspect="aspectfit" verticaloptions="start"/>           <image x:name="frontimg" aspect="aspectfit" verticaloptions="start"/>         </absolutelayout>       </stacklayout>     </scrollview>   </contentpage.content> </contentpage> 

what need simple, vertical scroll page few labels vertically stacked , after need create "one image" made of 3 images on top of each other (like 3 layers overlapped). need absolutelayout images, right?

i've tried possible combinations of verticaloptions views in file , nothing works.

the problem scroll leave big space under images. , green color, means absolutelayout not shrinking height after image resize. images can have variable sizes , shapes (although 3 inside each page have same dimensions) , larger smartphone screen (zoom feature later). need images use width available , keep aspect ratio (aspectfit believe).

all images embedded resources. here code behind carouselcontentpage:

public pointinfodatatemplate(pointmodel point) {     initializecomponent();     namelabel.text = point.nome;     desclabel.text = point.apelido;     backimg.source = imagesource.fromresource(point.backimg);     midimg.source = imagesource.fromresource(point.midimg);     frontimg.source = imagesource.fromresource(point.frontimg);     //backimg.sizechanged += delegate {     //    imgscontainer.layout(new rectangle(imgscontainer.bounds.x, imgscontainer.bounds.y, backimg.bounds.width, backimg.bounds.height));     //    mystacklayout.layout(new rectangle(imgscontainer.bounds.x, imgscontainer.bounds.y, backimg.bounds.width, backimg.bounds.height));     //}; } 

i tried resizing layouts after sizechanged event, didn't work either.

so maybe i'm doing wrong, here's code. i'm stuck in 3 days, don't know else do.

i tried using relativelayout scrollview.content. , after entire day trying understand (and not sure if did) had worse problem. relativelayout overflow scroll height , hide part of images behind tabs (base app container).

but i'd preserve stacklayout->items + absolutelayout approach.

i appreciate help.

i found out problem on absolutelayout not handling child resize events. either problem image element not dispatching proper events or absolutelayout not handling them well. needed create event handling. added listener image.sizechanged set absolutelayout height.

        private void backimg_sizechanged(object sender, eventargs e)         {             imgscontainer.heightrequest = backimg.height;         } 

that works case, if have more complex child disposition absolutelayout need that:

private void childadded_eventhandler(object sender, eventargs e) {     double neededheight = 0;     foreach(var child in sender) {         if(neededheight < child.y+child.height) {             neededheight = child.y+child.height;         }     }     sender.heightrequest = neededheight; } 

and have add event handler absolutelayout.childadded , absolutelayout.childremoved;


Comments

Popular posts from this blog

Why does Go error when trying to marshal this JSON? -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

python - Pygame. TypeError: 'pygame.Surface' object is not callable -