Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

How to do AbsoluteLayout for ViewCells with Labels?

$
0
0

Hi all:

TLDR: I'm looking for any sample code for correctly doing...
- ViewCells in a ListView
- using AbsoluteLayouts
- without setting any Proportional bits
- with uneven rows
- containing word-wrapping Labels

I have an app that requires ViewCells in a ListView with uneven rows containing word-wrapping Labels. I started with the standard design method, using nested StackLayouts and Grids. Works OK, but on my Android device the scrolling is slow and stuttering. So I switched to using AbsoluteLayouts, following the method Charles Petzold used in Chapter 14: I add a handler for the SizeChanged event & in there I make various AbsoluteLayout.SetLayoutBounds() calls. I calculate the required row size, and set the HeightRequest for that cell accordingly.

All of this works great on my iPhone and my Android 7" tablet. Scrolling is much faster and smoother.

THE PROBLEM is when I run it on an iPad. When the page first appears, the cells are sized oddly, with many cells being taller than they need to be. After the cells scroll off-screen, they come back looking perfect.

The 1st screen shot below shows what the initial page looks like. The 2nd one is after I scrolled everything off-screen and scrolled back up.

I've been struggling with this problem for the better part of a day now, and I'm stumped.

THE REASON this is happening, as best I can determine, is that each cell's SizeChanged event is called twice. The 1st time, the cell's Width is given as 320, so all word wrapping is calculated incorrectly. The 2nd time it gets the correct Width (760+). But apparently only the AbsoluteLayout.SetLayoutBounds calls I make on the 1st pass are displayed. The calls I make on the 2nd pass are what gets used after the cell goes off-screen and comes back on-screen.

Has anyone else been through this? Any help would be much appreciated.

Thanks,
Mike

P.S. - I know I could use custom renderers, but that's the "nuclear" option, and I'd prefer to avoid that if I possibly can. The AbsoluteLayout speed is acceptable to me -- I just need to get the layout working correctly on the 1st pass.


Viewing all articles
Browse latest Browse all 75885

Trending Articles



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