Set ListView's width according to elements?

Hi,

I have a ListView inside a RelativeLayout. How can I set the ListView's width to the width of its widest displayed row?

Best Answer

  • ShimmyWeitzhandlerShimmyWeitzhandler US ✭✭✭
    edited August 2017 Accepted Answer

    The solution was simply constraining the ListView's width to the RelativeLayout:

    _Container.Children.Add(_ListView, yConstraint: Constraint.RelativeToParent(rl => rl.Height),
      widthConstraint: Constraint.RelativeToParent(rl => rl.Width));
    

    Here's the full code.

Answers

  • N_BauaN_Baua INMember ✭✭✭✭✭

    @ShimmyWeitzhandler said:
    Hi,

    I have a ListView inside a RelativeLayout. How can I set the ListView's width to the width of its widest displayed row?

    Can I assume, you do not wish to "Word-Wrap" your content, within a Listview?
    Does FlowListView suit your requirement?

    Adding a screenshot of your requirement would provide more insight.

    Regards,
    N Baua

  • ShimmyWeitzhandlerShimmyWeitzhandler USMember ✭✭✭
    edited August 2017 Accepted Answer

    The solution was simply constraining the ListView's width to the RelativeLayout:

    _Container.Children.Add(_ListView, yConstraint: Constraint.RelativeToParent(rl => rl.Height),
      widthConstraint: Constraint.RelativeToParent(rl => rl.Width));
    

    Here's the full code.

Sign In or Register to comment.