Skip to main content

How to Show Gallery Rows of Different Heights in Power Apps

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

In an ordinary gallery every row has the same height, so a line of text that wraps on a phone loses its end. A flexible height gallery lets each row grow with its content: turn on Auto height for the labels, place each one below the one above, and a two-line row is simply taller.

The example is the list of people on the Reports screen of the Overtime Timesheet app. Each card shows a person's name, then their approved hours and departments, such as 10.00 hours in Emergency Department, Radiology.

My first version used an ordinary blank vertical gallery with rows 76 pixels high. On a phone, that line wrapped, and Radiology was cut off. Splitting the line in two, as in Fixed: Text Is Cut Off Inside a Container on Small Screens in Power Apps, would only move the problem: someone who works in three departments would wrap again. Microsoft's guide Show items of different heights in a canvas app gallery is for exactly this.

How It Works​

From Microsoft's guide:

  • A Flexible height gallery shows each item at the height its content needs.
  • Auto height on a label makes it grow or shrink to fit its content. The guide calls it the key to making the flexible height gallery work correctly: without it, all items render at the same fixed height.
  • Each control's Y is set based on the Y and Height of the control immediately above it, so it moves down when the one above grows.

Open Insert and search for flexible height. Two results appear: Flexible height gallery under Layout, and Blank flexible height gallery under Classic. I used the blank one, which starts with an empty template, like the app's other galleries:

The Insert pane searched for flexible height, with Flexible height gallery under Layout and Blank flexible height gallery under Classic

Set its Items and the rest of its properties as for any vertical gallery (How to Add a Vertical Gallery in Power Apps and Connect It to a SharePoint List). I set its TemplateSize to 76, the old rows' height.

Step 2: Put the Labels in the Template​

Select the gallery's template with the pencil icon at its top-left, then insert or paste the labels there. Here, two Text controls: lblPersonRS for the name and lblPersonHoursRS for the hours and departments. A control pasted with the gallery itself selected goes beside the gallery, not into its template (Fixed: New Control Lands Outside the Gallery Instead of Inside It in Power Apps).

Give each label X 16 and Width Parent.TemplateWidth - 32. Inside a gallery, Parent is the template.

Step 3: Turn On Auto Height​

Set AutoHeight to true on each label that can wrap:

lblPersonRS and lblPersonHoursRS → AutoHeight
true

The formula bar with the property AutoHeight selected and the formula true

Step 4: Place Each Label Below the One Above​

The first label sits at Y 12. The second follows it, wherever it ends:

lblPersonHoursRS → Y
lblPersonRS.Y + lblPersonRS.Height + 6

The formula bar with the property Y selected and the formula lblPersonRS.Y + lblPersonRS.Height + 6

If the name ever wraps, the hours line moves down with it.

Step 5: Leave Space Under the Last Label​

On a phone, the first run of this gallery put each card's last line right against the card's bottom edge: a row ended where its lowest control ended. A bottom padding on the last label gives the row that space back, because Auto height counts the padding in the label's height:

lblPersonHoursRS → PaddingBottom
16

The Result​

On a phone 390 pixels wide, the first card's line wraps onto two lines and its row is taller; the others stay on one line:

The Approved hours by person list on a phone with four cards: Admin User with 10.00 hours in Emergency Department, on one line and Radiology on the next in a taller card, then Aisha Khan 4.00 hours in Emergency Department, Maya Patel 3.75 hours in Radiology and Daniel Brooks 2.50 hours in Radiology

Common Mistakes​

MistakeWhat happensDo this instead
Auto height on in an ordinary galleryThe label grows, but the row doesn'tA flexible height gallery
A fixed Y for the second labelA wrapped first label covers itFirst.Y + First.Height + gap
No padding under the last labelThe text touches the next rowPaddingBottom on the last label

Troubleshooting​

SymptomLikely causeFix
Every row is the same heightAuto height is offTurn it on for the labels that wrap
Labels overlap in a tall rowThe lower label's Y is a numberChain it to the label above
A pasted label isn't in the rowsIt went beside the galleryPaste it into the template

FAQ​

When every row has the same content length, such as a name and a date. Microsoft's gallery reference notes one limitation of the flexible variant: if a user scrolls it before all items are loaded, the item in view can be pushed down when loading finishes.

Can images grow too?​

The same way: set the image's Y from the control above it. Microsoft's guide places an image below a growing label like this.

Conclusion​

For rows whose text can wrap, use a Blank flexible height gallery, turn on Auto height for the labels, chain each label's Y to the one above, and give the last label a bottom padding. Each row then grows with its content, on any screen.

Additional Resources​