Quantcast
Channel: User Liyun Zhang - MSFT - Stack Overflow
Viewing all articles
Browse latest Browse all 446

Answer by Liyun Zhang - MSFT for How to set AbsoluteLayout positions and dimensions dynamically on Android MAUI

$
0
0

I have tested your code and reproduced the issue. I found the problem wasbetween the layout changes and child resizing.

You can add the two lines code below at the beginning of the Button_Clicked。

var blueLayoutBounds = absoluteLayout.GetLayoutBounds(blueBox);var redLayoutBounds = absoluteLayout.GetLayoutBounds(redBox);

And then you will see the value is correct. The layout changes requested in OnSizeAllocated is successful.

But if you use the var blueHeight = blueBox.Height, you will find the value is 0. So it seems the layout changes didn't notify the BoxView to resize. You can report this on the repo.

And for a workaround, you can set the HeightRequest for the BoxView manually:

protected override void OnSizeAllocated(double width, double height){    base.OnSizeAllocated(width, height);    double availableHeight = height - topBar.Height;    _blueRect = new Rect(0, 0, width, availableHeight * 0.7);    _redRect = new Rect(0, _blueRect.Height, width, availableHeight * 0.3);    absoluteLayout.SetLayoutBounds(blueBox, _blueRect);    absoluteLayout.SetLayoutBounds(redBox, _redRect);    blueBox.HeightRequest = availableHeight * 0.7;    redBox.HeightRequest = availableHeight * 0.3;}private void Button_Clicked(object sender, EventArgs e){    double availableHeight = Height - topBar.Height;    _blueRect = new Rect(0, 0, Width, availableHeight * 0.4);    _redRect = new Rect(0, _blueRect.Height, Width, availableHeight * 0.6);    absoluteLayout.SetLayoutBounds(blueBox, _blueRect);    absoluteLayout.SetLayoutBounds(redBox, _redRect);    blueBox.HeightRequest = availableHeight * 0.4;    redBox.HeightRequest = availableHeight * 0.6;}

Viewing all articles
Browse latest Browse all 446

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>