Can you have dynamic cell heights with either the ListView or TableView views?

PhilRyanPhilRyan ✭✭AUMember ✭✭

Can you have dynamic cell heights with either the ListView or TableView views?

«13

Answers

  • MartinBoothMartinBooth ✭✭ USMember ✭✭

    Trying to do the same thing, and it doesn't seem to make a difference whether HasUnevenRows is set to true or not.. The rows are all the same height. What's more is it would be great if Xamarin.Forms could expand the height of the cells to accomodate the content for me, rather than making me calculate the height... either way though, I can't get anything to work at the moment!

  • MartinBoothMartinBooth ✭✭ USMember ✭✭

    From the looks of things, HasUnevenRows is not implemented for the ListView, but it is for the TableView (I'm looking at IOS).. for the TableView there is a renderer UnEvenTableViewModelRenderer which overrides GetHeightForRow in the UITableViewSource... no such equivalent exists in the ListView from what I can see.

    Unfortunately, it doesn't seem extensible enough to easily add this functionality myself.

  • Stefan.de.VogelaereStefan.de.Vogelaere USMember

    Any news on this bug @JasonASmith or a confirmation on how to fix this? thx.

  • TroyWillmotTroyWillmot NZMember, University

    Am having the same issue. Are there any plans for Xamarin to update the renderer for iOS to handle this on a ListView?

  • RunarOvesenHjerpbakkRunarOvesenHjerpbakk ✭✭ NOUniversity ✭✭

    Plus one for this!

  • EricMaupinEricMaupin Xamurai USXamarin Team Xamurai

    HasUnevenRows was fixed for ListView on iOS in 1.2.1

  • CraigDunnCraigDunn Xamurai USXamarin Team Xamurai

    I posted a super-simple example over here which links to the Evolve 13 sample Session list and cell.

  • AlexFawcettAlexFawcett GBMember

    @ermau‌ - has HasUnevenRows been fixed in TableView as well? Doesn't seem to be working for me in 1.2.1.

    thanks

  • EricMaupinEricMaupin Xamurai USXamarin Team Xamurai

    @Al316‌ Can I see how you're using it? It was never (to my knowledge) broken for TableView.

  • Matt.CookMatt.Cook ✭✭ USMember ✭✭

    @MartinBooth‌ Thanks for ListView code for allowing editable fields!

    Does anyone know how to make this work for a TableView as well? Simply setting it to be the type of TableView in the reflection call doesn't seem to work, as I am assuming the reason being the source is gotten a different way.

  • DanielHalan.1320DanielHalan.1320 SEMember

    +1, any progress on this issue? as there is a bug report on 'HasUnevenRows not working/implemented on iOS' that currently got "Resolved Invalid" status
    https://bugzilla.xamarin.com/show_bug.cgi?id=22535

  • rudyrykrudyryk ✭✭✭ RUMember ✭✭✭
    edited February 2015

    @DanielHalan.6266 HasUnevenRows partially works for me for TableView and for ListView. I mean, I can have list or table with different height rows, all I need is to calculate height first.

    Calculating height could be tricky though and result code is not really nice, but it works and that's better than nothing :)

    Here's my gist for measuring text size on iOS:
    https://gist.github.com/rudyryk/7b9633e847e727d12de7

  • rudyrykrudyryk ✭✭✭ RUMember ✭✭✭

    Does anybody know how to "refresh" TableView after setting new height for already displayed cell?

    It seems like setting new height is just ignored.

  • DemiVisionDemiVision ✭✭ USMember ✭✭
    edited March 2015

    'HasUnevenRows' seems to work correctly for me on iOS. On Android, I have to set the Height of each cell individually. Setting 'RowHeight' on the parent ListView without setting the height within the cell causes bizarre behavior.

  • AntonMakarevich.4563AntonMakarevich.4563 BYMember

    my question is similar to Alexey's. Is it a way to force cell resize dynamically after binding is done? basically I have a listview with custom viewcell which has grid with 2 rows. first row is always visible, the second one should be visible only when item is selected. so height of selected row is not equal to height of other rows. This behavior works perfectly on Android, but on iOS, it seems to ignore resizing of cell's content, so it messed with the content of next cell. my temporary workaround is to hide next cell, but I need a better solution...

  • AntonMakarevich.4563AntonMakarevich.4563 BYMember

    very ugly workaround for my problem.
    1) modify collection with some dummy item
    page.cs:

            Item _ph1 = new Item() { Title = "1", IsVisible = false };
            void ItemTapped(object sender, ItemTappedEventArgs e)
                    {
                        var item = e.Item as Item;      
                        if (item.IsSelected)
                             item.IsSelected = false;
                        else
                        {
                            foreach (var itm in _viewModel.Items)
                                itm.IsSelected = false;
                            item.IsSelected = true;
                        }
                 if (Device.OS == TargetPlatform.iOS)
                        {
                            if (_viewModel.Items.Contains(_ph1))
                                _viewModel.Items.Remove(_ph1);
                            else
                               _viewModel.Items.Add(_ph1);
                        }
                        listViewItems.SelectedItem = null;
                    }
    

    2) manually set height of the cell
    mycell.cs:

        protected override void OnBindingContextChanged()
                {
                    base.OnBindingContextChanged();
                    if (Device.OS == TargetPlatform.iOS)
                    {
                        var item = BindingContext as Item;
                        item.PropertyChanged -= item_PropertyChanged;
                        item.PropertyChanged += item_PropertyChanged;
                    }
                }
            void item_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "IsSelected")
                {
                    var item = sender as Item;
                    Height = (item.IsSelected) ? 300 : 100;
                }
            }
    
  • HrishiDHrishiD ✭✭ INMember ✭✭
    edited May 2015

    @AntonM Do you have any solution for this I am having same problem.
    @ermau I am working on accordion list View for iOS. It all works fine when I specify ListView Height in XAML.
    But I want cells to adjust according to the content without specifying height to cell.

  • AntonMakarevich.4563AntonMakarevich.4563 BYMember

    @HrishiD I posted my workaround in the prev post, I know it's a little bit stupid, but I didn't find any other solution as it looks like cell high (on ios) is recalculated only when itemssource is updated...

  • HrishiDHrishiD ✭✭ INMember ✭✭
    edited May 2015

    @AntonM I too did the same thing. I created accordion list View with ViewCell and Set height of view Cell by calculating length of each element in a view cell.

    I have one question how different screen sizes will be handled for Icons.
    do I need to create png files for 4s 5s and 6s (i.e for iOS I am talking) ?
    do I need to write code to detect screen size and then set Icons and images for that particular screen?
    if any one could answer that will be great.

  • DragosPopescuDragosPopescu ROMember

    Almost a year later, this annoying bug is still not fixed!!!

  • YuriShteinmanYuriShteinman ✭✭ CAUniversity ✭✭

    Really annoying!

  • tush100tush100 ✭✭ INMember ✭✭

    Any solution for dynamic row height. I cant able to see code.

  • tusharthakartusharthakar USMember

    Any solution for dynamic row height . I can't able to see code.

  • tusharthakartusharthakar USMember

    Any

  • tusharthakartusharthakar USMember

    Any

  • alex.2418alex.2418 USMember

    Any

  • alex.2418alex.2418 USMember

    Any solution for dynamic row height. I cant able to see code.

  • Chris.3704Chris.3704 ✭✭ USUniversity ✭✭

    Have you tried setting the HasUnevenRows property to true?

  • TheosTheos ✭✭ NLBeta ✭✭

    I've tried many solutions too, not working at all.
    My content in my cell is updated when the RefreshControl is finished and then the cell height isn't updated untill I've scrolled that cell out of the screen shortly.
    My content is very dynamic so can't set the height myself.

    So i'm posting the question as well.. Any update on this?

  • XamDXamD PKMember

    Any Solution of this problem??

  • AlfredoRomeroAlfredoRomero ✭✭ USUniversity ✭✭

    I have exactly same issue, I need to change row height after tap, my rows don't refresh until listview scroll (re-draw) Any help on this??? custom render?? any sample code??
    thanks !

  • JohnHJohnH ✭✭✭✭✭ GBMember ✭✭✭✭✭
    edited February 2016

    I have the same issue, a custom cell that I want to change the height of depending upon user input. As others have said, in iOS setting the cell height after it has been rendered does nothing until the user forces a refresh by scrolling or rotating the device.
    Based on an earlier suggestion I am going to try to add another cell to the table view (Im not using binding for this) and then immediately remove it to see if it triggers an invalidate or refresh or something that will allow the new cell height to be used. That is a complete fudge though, I should be able to call an Invalidate or Refresh or something like that to force a recalc.

  • TheosTheos ✭✭ NLBeta ✭✭

    @JeroenBoumans.6481 said:
    This worked for me:

    HasUnevenRows = true, RowHeight = -1,

    Are you sure? Because 'RowHeight = -1' didn't change anything for me.

  • Whitchurch.6690Whitchurch.6690 ✭✭ USMember ✭✭

    @JeroenBoumans.6481 your solution has actually worked, for me in my listview that was dynamically adding newer items into the list, during the apps execution. It has resized the listview, although at the moment all my images look magnified.

    Thanks for your solution it works, but for the aesthetics of the UI that are messed up.

Sign In or Register to comment.