erchenger / sizeadjustingtextview Goto Github PK
View Code? Open in Web Editor NEWThis is based on an open source autosizing textview for Android.
License: GNU General Public License v2.0
This is based on an open source autosizing textview for Android.
License: GNU General Public License v2.0
Hi!
Please set screenshots.
Can you also include an example project?
so that we could use it easily.
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 :
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 .
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;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.