Skip to content

AutoResizeTextView doesn't wrap content when has new line character in the string ('\n') #37

Description

@overcomer

I use AutoResizeTextView and set the string in strings.xml such as "This is a string\nwith new line character". The string will displayed as a very small text.

I think the issue is in isValidWordWrap method, it doesn't include (before == '\n') as a valid word wrap. I have tested by adding (before == '\n') in isValidWordWrap method as following:

public boolean isValidWordWrap(char before, char after) {
      return before == ' ' || before == '-' || before == '\n';
}

And it will work as expected.

Activity

  1. AndroidDeveloperLB commented on Sep 27, 2016

    @AndroidDeveloperLB
    Owner

    The idea is that the TextView will wrap the text automatically for you, so there is no use for "\n" , and therefore no need to check for it.
    Do you think I should add this?

  2. tagy commented on Nov 21, 2016

    @tagy

    I agree with overcomer, I am displaying content from a server that sometimes contains new line characters.

    I have modified the isValidWordWrap method as above.

  3. tagy commented on Nov 21, 2016

    @tagy

    Also having a '\n' at the end of the string throws a StringIndexOutOfBoundsException.

    I updated the isValidWordWrap to remove the second unused parameter:

    public boolean isValidWordWrap(char before) { return before == ' ' || before == '-' || before == '\n'; }

    and the call to this method:

    if (i < lineCount - 1 && end > 0 && !isValidWordWrap(text.charAt(end - 1)))

    This seems to be working for me.

  4. AndroidDeveloperLB commented on Nov 28, 2016

    @AndroidDeveloperLB
    Owner

    You think I should add this fix?
    If so, can you please put a pull request?

  5. AndroidDeveloperLB commented on Jan 16, 2017

    @AndroidDeveloperLB
    Owner

    @tagy Can you please make a pull request?

  6. tagy commented on Jan 23, 2017

    @tagy

    Hi, Sorry I have not been working on Android for a while. I will try to look at this again in a week or so and make a pull request.

  7. DhamodharanS commented on May 8, 2017

    @DhamodharanS

    This issue is still exists in latest version also. can you have look on this. This works good even we may not check condition for **before == '\n'** also.

    if (i < lineCount - 1 && end > 0 && !isValidWordWrap(text.charAt(end - 1)))

  8. AndroidDeveloperLB commented on May 8, 2017

    @AndroidDeveloperLB
    Owner

    guys if you have found a nice working solution, please do a PR and I will use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions