locked
ScrollView with a Label cut bottom text on Android Vertical mode RRS feed

  • Question

  • User296721 posted

    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();
    }
    

    `

    Monday, April 10, 2017 1:29 PM

Answers

  • User329130 posted

    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 :)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, September 5, 2017 9:03 AM

All replies

  • User296721 posted

    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.

    Tuesday, April 11, 2017 11:03 AM
  • User89714 posted

    @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.

    Tuesday, April 11, 2017 11:12 AM
  • User296721 posted

    @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?

    Tuesday, April 11, 2017 11:23 AM
  • User89714 posted

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

    Tuesday, April 11, 2017 11:25 AM
  • User296721 posted

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

    Tuesday, April 11, 2017 12:34 PM
  • User330018 posted

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

    Monday, June 12, 2017 8:20 AM
  • User296721 posted

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

    Tuesday, June 13, 2017 8:44 AM
  • User329130 posted

    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 :)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, September 5, 2017 9:03 AM
  • User296721 posted

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

    Tuesday, September 5, 2017 9:10 AM
  • User329130 posted

    Welcome :) We wont tell anybody ;)

    Tuesday, September 5, 2017 9:14 AM
  • User315050 posted

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

    Tuesday, September 5, 2017 11:13 AM