ScrollView with a Label cut bottom text on Android Vertical mode

RasmusVindRasmusVind USMember ✭✭

Hi
I need to show the user an long eula text.
I have an Label in a ScrollView i a Grid.

This code works on iOS and on Android in landscape mode?!?!?
but in Vertical mode on android it cut the text off about when there is about 20% left.

Does anybody have an idea what is going on?

(the "HeaderView" is just a gridview that i use to display a header)

`

public eulaAcceptPage(string eula)
{
    this.eula = eula;
    InitializeComponent();
    setlayout();
}

private void InitializeComponent()
{
    header = new HeaderView( text.consent(), text.back(), false);
    buttomHeader = new HeaderView(text.no(), text.giveConsent(), text.yes());

    consentText = new Label {
        Text = eula,
        LineBreakMode = LineBreakMode.WordWrap,
    };

    scrolltextView = new ScrollView {
        Orientation = ScrollOrientation.Vertical,
        Content = consentText,
    };

}

private void setlayout()
{
    Padding = new Thickness(1, Device.OnPlatform(20, 0, 0), 1, 5);

    grid = new Grid
    {
        VerticalOptions = LayoutOptions.FillAndExpand,
        HorizontalOptions = LayoutOptions.FillAndExpand,
        RowDefinitions =
        {
            new RowDefinition { Height = new GridLength(60, GridUnitType.Absolute) },   //0
            new RowDefinition { Height = GridLength.Auto },                             //1
            new RowDefinition { Height = new GridLength(60, GridUnitType.Absolute) },   //2
        },
        ColumnDefinitions =
        {
            new ColumnDefinition { Width = GridLength.Star }, //0
            new ColumnDefinition { Width = GridLength.Auto }, //1
            new ColumnDefinition { Width = GridLength.Star }, //2
        }
    };

    grid.Children.Add(scrolltextView, 0, 3, 1, 2);

    grid.Children.Add(header, 0, 3, 0, 1);
    grid.Children.Add(buttomHeader, 0, 3, 2, 3);

    Content = grid;
}

protected override void OnDisappearing()
{
    header.leftButton.Clicked -= backButton_Clicked;
    buttomHeader.rightButton.Clicked -= ConsentGivenButton_Clicked;
    base.OnDisappearing();
}

protected override void OnAppearing()
{
    header.leftButton.Clicked += backButton_Clicked;
    buttomHeader.rightButton.Clicked += ConsentGivenButton_Clicked;
    base.OnAppearing();
}

`

Best Answer

  • StasIegorovStasIegorov USMember
    Accepted Answer

    Hey, I just faced the same issue in my project. Until guys from Xamarin finally remove that nasty limitation for 100 lines of text in a Label for Android the workaround for me is to create custom label inherited from Label class and then use a custom renderer like this:

    public class UnlimitedTextLabelRenderer : LabelRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
            {
                base.OnElementChanged(e);
    
                Control?.SetMaxLines(int.MaxValue);
            }
        }
    

    Hope this helps :)

Answers

  • RasmusVindRasmusVind USMember ✭✭
    edited April 11

    If I add more text it also cut off on android in landscape mode.
    if i set the MinimumHeightRequest (on the label/scrollview and boath) to the contentSize it has no effect.
    if i set the text in "OnAppering" it has no effect.
    i have split the string up in smaller labels and put that in a stacklayout and that in a scrollview and still it do it.

  • JohnHardmanJohnHardman GBUniversity ✭✭✭✭✭

    @RasmusVind - I've logged bugs relating to ScrollView not allowing the user to scroll right to the bottom of the ScrollView content on Windows platforms. One common scenario when this happens is when there are Label views contained within the ScrollView content and the text of the Label wraps onto 2 or more lines.

    I am seeing the same thing happening on Android, but not iOS. I'm pretty sure that this was not happening on Android 6+ months ago, but cannot be 100% certain of that. I haven't built a small repro project showing this on Android yet. If you have one available, I suggest raising a bug in Bugzilla and attaching your code.

  • RasmusVindRasmusVind USMember ✭✭

    @JohnHardman that sound bad :(
    The "funny" this is that i can see on the scroll indicator that i have scrolled to the bottom.
    But i will try to make a sample project and report it.
    Have you found any kind of workaround?

  • JohnHardmanJohnHardman GBUniversity ✭✭✭✭✭

    @RasmusVind - I haven't got a workaround :-(

  • RasmusVindRasmusVind USMember ✭✭

    now reported at https://bugzilla.xamarin.com/show_bug.cgi?id=55023
    But if anyone knows a workaround i will buy them a beer.

  • plv.9622plv.9622 USMember

    Are there any news? Is it possible to know when a fix will be released?

  • RasmusVindRasmusVind USMember ✭✭

    Its confirmed in BugZilla... but no news on a fix...
    i ended up making a WebView to show the text...

  • StasIegorovStasIegorov USMember
    Accepted Answer

    Hey, I just faced the same issue in my project. Until guys from Xamarin finally remove that nasty limitation for 100 lines of text in a Label for Android the workaround for me is to create custom label inherited from Label class and then use a custom renderer like this:

    public class UnlimitedTextLabelRenderer : LabelRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
            {
                base.OnElementChanged(e);
    
                Control?.SetMaxLines(int.MaxValue);
            }
        }
    

    Hope this helps :)

  • RasmusVindRasmusVind USMember ✭✭
    edited September 5

    thanks mate that does it. :smiley:
    lets hope no one ever puts 2,147,483,647 lines in a lable ;)

  • StasIegorovStasIegorov USMember

    Welcome :) We wont tell anybody ;)

  • userexperienceuserexperience SGMember ✭✭

    Thanks.I will use it in my android app development.

Sign In or Register to comment.