Coder Social home page Coder Social logo

sizeadjustingtextview's Issues

Bug: very slow , truncates text and puts characters on next line

All I wanted is that it would fit into it boundaries.

Using the next XML will make it very slow and also truncate the text:

<com.omitneedlesscode.sizeadjustingtextview.SizeAdjustingTextView
    android:layout_width="180dp"
    android:layout_height="203dp"
    android:layout_below="@+id/text_input"
    android:maxLines="2"
    android:text="content text sample"
    android:textSize="1000dp"/>

And this is what I got :

device-2016-02-09-162003

plus it was very slow.

note that I've set 1000dp so that it will resize to the max that it can. a better way is to do it in code.

I think it should work this way:
using the current configurations of the TextView, if it failed to fit, try to find a font that will make it fit.
if failed with this, try to add a line (till reaching max lines that were set), and for each iteration there try to fit the font.

For the font checking, I think it should use binary search, instead of decreasing by 1 .

Doesn't work when increasing the view's height.

Here's how to fix it.

private float findNewTextSize(int width, int height, CharSequence text) {
        TextPaint textPaint = new TextPaint(getPaint());
        float targetTextSize = getMaxTextSize();  // Start from the max size
        int textHeight = getTextHeight(text, textPaint, width, targetTextSize);
        while(textHeight > height && targetTextSize > mMinTextSize) {
            targetTextSize = Math.max(targetTextSize - 1, mMinTextSize);
            textHeight = getTextHeight(text, textPaint, width, targetTextSize);
        }
        return targetTextSize;
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.