grantland / android-autofittextview Goto Github PK
View Code? Open in Web Editor NEWA TextView that automatically resizes text to fit perfectly within its bounds.
License: Apache License 2.0
A TextView that automatically resizes text to fit perfectly within its bounds.
License: Apache License 2.0
I used AutofitTextView with xml and the text was nearly two times larger on a Nexus 5 (API21) than on Nexus 7 (2013, API21) or Nexus 4 (API15). Using "AutofitHelper.create(textView);" with a normal TextView worked. Maybe there is a problem with xxhdpi devices?
<me.grantland.widget.AutofitTextView
android:id="@+id/tv_description"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:lineSpacingExtra="6sp"
android:textColor="@color/black"
android:textSize="12sp"
autofit:minTextSize="8sp"/>
When using lineSpacingExtra, resizing doesn't work.
I'm using AutofitTextView in a LinearLayout (A):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="60dp"
android:layout_height="match_parent"
android:padding="0dp">
<me.grantland.widget.AutofitTextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
/>
<!-- old code
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
/> -->
</LinearLayout>
From my AppWidgetProvider, I'm dynamically adding some linear layout A.
On the device the Widget is not loading, an error is displayed: "Problem loading widget", but I don't see any error on logcat.
How to import you library in eclipse?
Probably will utilize StaticLayout.
I would suggest you add a group name attribute so that multiple textviews can synchronize their sizes. The smallest one will set the size of the rest.
Hi,
Firstly I thank you for this library. It works for me well. I use autofitTextView to resize my text widgets. In Addition to I want to add kerning into your library. I have created a custom view extending your autofitTextView class, and I have tried to add kerning code into my custom view class. My code didn't work as I want. I am giving you my code, maybe you can help me.
public class KerningSizeAdjustingTextView extends AutofitTextView
{
private float spacing = Spacing.NORMAL;
// Default constructor override
public KerningSizeAdjustingTextView(Context context) {
this(context, null);
}
// Default constructor when inflating from XML file
public KerningSizeAdjustingTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
// Default constructor override
public KerningSizeAdjustingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public float getSpacing() {
return this.spacing;
}
public void setSpacing(float spacing) {
this.spacing = spacing;
applySpacing();
}
private void applySpacing() {
if (this == null || this.getText() == null) return;
StringBuilder builder = new StringBuilder();
for(int i = 0; i < getText().length(); i++) {
builder.append(getText().charAt( i ));
if(i+1 < getText().length()) {
builder.append("\u00A0");
}
}
SpannableString finalText = new SpannableString(builder.toString());
if(builder.toString().length() > 1) {
for(int i = 1; i < builder.toString().length(); i+=2) {
finalText.setSpan(new ScaleXSpan((spacing+1)/10), i, i+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
super.setText( finalText, BufferType.SPANNABLE );
}
public class Spacing {
public final static float NORMAL = 0;
}
}
Actually I just want two properties for my text view . Rightly, TextView will be resized and kerning.
How can I add a stroke for content of text?
I tried to override onDraw with Paint.Style.STROKE but it's too difficult to locale position of stroke text.
Anyone can help me? thanks a lot!
I have a text view that needs to have a fixed width, but can have a max of two lines. What I would like is if the text is a single word that it be autofit to the first line, but if the text is multiple words, it should use both lines. The behavior that I get now is that the single word wraps onto the second line instead of autofitting.
In the following example, my intention is to have the string ABCDEFGH autofit a single line, but since maxLines is 2, the autofit allows it to wrap to the next line, so H ends up on the second line by itself.
<me.grantland.widget.AutofitTextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="ABCDEFGH"
android:textSize="20dp"
android:maxLines="2"/>
Can a mechanism be added to allow the autofit logic to look to see how many words are in the string and attempt to treat single word strings as a single line?
i get this error when when want add it to android studio:
Error:Failed to find: me.grantland:autofittextview:0.2.+
I am attempting to use your textview with it's height set as wrap-content within a fragment.
However, when the text is set BEFORE the text view is drawn (so in the fragment's onCreateView), the text gets resized, but the size of the TextView itself does not.
This ends up getting remedied the next time a sibling view is updated; resulting in a jarring UI experience as the textview all of a sudden shrinks to the correct size (moving the sibling views as well).
If the text is resized once the view is drawn, it works as intended. Have you experienced this issue before, and if so, do you have a workaround?
Here are a couple of things that would make subclassing AutoFitTextview more useful:
Provide a way to get the current actual text size.
You overrode getTextSize like this:
public float getTextSize() {
return mMaxTextSize;
}
May you could do this instead:
public float getMaxTextSize() {
return mMaxTextSize;
}
or
public float getTextSize() {
return mMaxTextSize;
}
public float getCurrentTextSize() {
return super.getTextSize();
}
Also, provide a way for subclasses to get notified when the text size is updated:
public void onTextSizeWasAutoFitted(int size){}
Hi,
Request that you integrate a reworked StrokedTextView into your app.
The problem with StrokedTextView is that if you use a heavy stroke - say 12 - the TextView gets cropped on the right. It just doesn't expand the canvas properly to account for the addition of the outline.
I've looked at all available variations of "How to outline a TextView" I could find - and they all suffer the problem of not expanding the canvas width calculations.
Thank you.
When using textAllCaps parameter the size of the text is not correctly calculated.
Expected Behavior:
When you retrofit existing TextViews and change them to AutoFitTextViews in xml, they should resize correctly as more text is added to field.
Observed Behavior:
TextViews changed to AutoFitTextViews Don't resize correctly to the Default min size (8sp)
Reproducible Test:
In the project sample, remove the following line in main.xml
autofit:minTextSize="8sp"
see screenshot below
Reason:
AutoFitHelper.java:66 int minTextSize = (int) helper.getMinTextSize();
AutoFitHelper.java:75 minTextSize = ta.getDimensionPixelSize(R.styleable.AutofitTextView_minTextSize, minTextSize);
both of the returned sizes above are in Pixels...
AutoFitHelper.java:80 helper.setMinTextSize(minTextSize)
This method signature applies SP as no TypedUnit is specified. So, taking my density into account (xxhdpi) the density factor is 3. The min was/should be 24px but then the above method changed it to 72px
Proposed Solution:
change AutoFitHelper.java:80 to
helper.setRawMinTextSize(minTextSize);
helper.setPrecision(precision);
Is it possible to use a lower value for minSdkVersion? Currently, AutofitTextView is the reason why my app is forced to use minSdkVersion=14 and it would be really great to support version 10.
HI!
Add:
app:minFontSize="12sp"
Error:
When set, for example, android: maxLines = " 3 " the text of the two words is broken down into all 3 lines instead of 2.
Example:
Ивано
в
Иванович
Hi! i'm new with Android development and i tried to use your code with TextClock. It doesn't work.
I tried also to extend Textclock cloning your AutofitTextView with no success... can you help me?
<me.grantland.widget.AutofitLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextClock
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
/>
</me.grantland.widget.AutofitLayout>
<com.example.valenti.healthwatch.AutofitTextClock
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/orologio"
android:textSize="50sp"
autofit:minTextSize="8sp"
android:gravity="center"
android:singleLine="true"
android:layout_centerInParent="true"/>
hi i have tried your view but i don't get any text, the view stay empty ??
I'm not for sure but I think the create()
method in AutofitHelper.java
, this line helper.setMinTextSize(minTextSize).setPrecision(precision);
is not right. You should call setRawMinTextSize()
rather than call setMinTextSize()
. And I have reasons for this: I notice that getDimensionPixelSize()
method returns size in pixel not in sp
or dp
, as we go deep inside, we can find that this method already converts sp
to px
! if you call setMinTextSize()
method, you will convert it again! So I think this line should be changed to something like helper.setRawMinTextSize(minTextSize).setPrecision(precision);
Am I right? Thank you!
text does not auto-fit when using support library com.android.support:appcompat-v7:21.0.0
am i the only one with this issue?
Hi,
When I git clone
and attempt to build this project from the command line using gradle build
, this is what I see:
/Users/me/Desktop/android-autofittextview/library/src/main/java/me/grantland/widget/AutofitTextView.java:12: error: unknown tag: attr
* @attr ref R.styleable.AutofitTextView_minTextSize
17 errors
43 warnings
:library:androidJavadocs FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':library:androidJavadocs'.
Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '/Users/ericsilverberg/Desktop/android-autofittextview/library/build/tmp/androidJavadocs/javadoc.options'
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
While trying with various Japanese strings, I've encountered a StackOverflowError:
java.lang.StackOverflowError
at android.text.TextUtils.getChars(TextUtils.java:73)
at android.text.MeasuredText.setPara(MeasuredText.java:106)
at android.text.StaticLayout.generate(StaticLayout.java:239)
at android.text.StaticLayout.<init>(StaticLayout.java:140)
at android.text.StaticLayout.<init>(StaticLayout.java:90)
at android.text.StaticLayout.<init>(StaticLayout.java:68)
at android.text.StaticLayout.<init>(StaticLayout.java:48)
at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:297)
at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:306)
at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:306)
at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:306)
at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:306)
at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:306)
// goes on repeating ......
getTextSize() gets caught in an infinite loop while doing a binary search looking for the best size.
The String I'm trying to display is this:
キスアト
Note that this is not the only String that crashes, any random Japanese Strings could cause a crash.
Another example
美少女写真館 番外編 OUTSIDE STORY
This seems to be related to encoding....
Hello.
What I want to achieve is exactly what is shown on animation.
But, if I set android:singleLine="true"
text never expands to second line.
If single line is not set, resizing don't work.
Even if I run your demo, text is always in one line.
How to make it behave as on animated gif?
I´m creating a list view with a lot of fields and with S4 the fiels don´t make the autofit. I think that the problem is the little space available.
In S4
What should appear
The code
<me.grantland.widget.AutofitTextView
android:id="@+id/data_entrada"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="16"
android:singleLine="true"/> <!-- obrigatório -->
Do you have any quick fix?
Thanks
using dependency 'com.google.android.support:wearable:1.2.0' and gives the following error:
Attribute "minTextSize" has already been defined
Hello,
I have a bug using your useful nice lib when I set a SpannableString to AutofitTextView : the text doesn't fit at all (it's really little compared to the possible max size). Is this a known problem and is it possible to fix it (I also tried with a TextView within a AutofitLayout but result is the same) ?
Thank you !
Below is my code in XML that adds a drawable icon to the textview. The text resizes but is always slightly too large for the button. I think this class does not consider the offset from the drawable:
<me.grantland.widget.AutofitTextView
android:layout_width="150dp"
android:layout_height="35dp"
android:text="VEHICLE"
android:id="@+id/order_button_vehicle"
android:textColor="@color/honk_order_help_button"
android:background="@drawable/order_help_button"
android:textSize="14sp"
android:drawableLeft="@drawable/icon_car"
android:drawableStart="@drawable/icon_car"
android:drawablePadding="5dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:layout_alignBottom="@+id/order_button_payment"
android:layout_toRightOf="@+id/centerView"
android:layout_toEndOf="@+id/centerView"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:singleLine="true"
autofit:minTextSize="6sp"
/>
Right now, you are calling
String text = getText().toString();
This makes AutoFitTextView not render Spannables correctly.
Instead, just do:
CharSequence text = getText();
You can just use the CharSequence everywhere, e.g.:
mPaint.measureText(text, 0, text.length())
Also, the StaticLayout constructor takes a CharSequence
Text height is not measured and considered. So, when a single line short text (like HELLO) with big textview width and small textview height is used, the size will be too big for the height.
The following method can be used to determine the height.
private int getTextHeight(CharSequence text, TextPaint paint, int targetWidth, float textSize) {
TextPaint paintCopy = new TextPaint(paint);
paintCopy.setTextSize(textSize);
StaticLayout layout = new StaticLayout(text, paintCopy, (int)targetWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
return layout.getHeight();
}
At the end of "void refitText()" method, using the following code would solve the problem:
while(getTextHeight(text, mPaint, targetWidth, size) > targetHeight) {
size--;
}
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
Hi could you help me and tell me how i have to do to add you library in my Eclipse project ?
There is an important fixed bug affecting Android 3.1 - 4.04 causing all AutoResizingTextView widgets not to work. Please read: http://stackoverflow.com/a/21851157/2075875
Currently AutofitTextView doesn't work correctly when using android:layout_width="wrap_content". The view will only decrease in size.
Using android:layout_width="match_parent" is not an option, because in need to have a second view next to it which moves when the AutofitTextView gets bigger.
I think I have found a solution and will sent a PR
Hello!
I have a problem with the following code
textView = new TextView(getContext());
textView .setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
// ...
AutofitHelper.create(textView)
.setMinTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
within Fragments (FragmentStatePagerAdapter).
On each fragment there are person names (textView) getting autofitted using your class. That works great until i reach another fragment where the height of the textview is getting changed.
When i scroll back to the other fragment, the text size stays the same like before but the height of the textview is increased to the higher one.
Looks like all textviews in the fragment will be normalized to the same height or even to the same line height...
Is there a way around that behavior?
Or is it a problem of the Fragment.SavedState instead of AutofitHelper?
I tried to requestLayout() at onPageSelected(int). That works at all but i would need to call requestLayout also on every getViewPager().setCurrentItem() because it is not calling onPageSelected. Maybe theres an easier/better way?
Thank you!
Best Regards,
Juergen
Hey,
I have used this library.
Its working fine if i am using in any view.
But when i integrate this library with list view. It changing text size randomly.
Let me add my code here, I have added this code inside my list item.
<me.grantland.widget.AutofitTextView
android:id="@+id/tvAudience"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center_vertical"
android:text="Publifhbgdfgdfgfggfgc"
android:maxWidth="@dimen/max_width_targetaudience"
android:singleLine="true"
android:textColor="@color/blue_text" />
Can anyone help me to resolve this issue?
Thanks
I saw that for release 0.2.1, there is a fix for:
Fix minTextSize set from attrs
How can I use this setting if i am importing with maven?
i found that change the AutoFitTextView font size, style on Runtime exist issue.
Thanks
When I switch the screen from landscape to portrait mode, I get a Null Pointer Exception. I did not have this problem before adding the me.grantland.widget.AutofitTextView.
01-03 22:35:24.841 17553-17553/com.northeast_cc.plugmyband E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.northeast_cc.plugmyband, PID: 17553
java.lang.RuntimeException: Unable to retain activity {com.northeast_cc.plugmyband/com.northeast_cc.plugmyband.PlugMyBand}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object com.northeast_cc.plugmyband.AsyncTaskManager.retainTask()' on a null object reference
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4840)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4889)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5142)
at android.app.ActivityThread.access$1100(ActivityThread.java:205)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1701)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6895)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object com.northeast_cc.plugmyband.AsyncTaskManager.retainTask()' on a null object reference
at com.northeast_cc.plugmyband.PlugMyBand.onRetainNonConfigurationInstance(PlugMyBand.java:711)
at android.app.Activity.retainNonConfigurationInstances(Activity.java:2004)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4836)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4889)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5142)
at android.app.ActivityThread.access$1100(ActivityThread.java:205)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1701)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6895)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
I get a crash in the hardware layer on pre lollipop devices when trying to copy and paste. All I do is long press on the view to get this to happen.
java.lang.RuntimeException: createWindowSurface failed EGL_BAD_ALLOC
at android.view.HardwareRenderer$GlRenderer.createSurface(HardwareRenderer.java:1351)
at android.view.HardwareRenderer$GlRenderer.createEglSurface(HardwareRenderer.java:1243)
at android.view.HardwareRenderer$GlRenderer.initialize(HardwareRenderer.java:1060)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1546)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5139)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
AutofitTextView.java defines the TAG constant as "me.grantland.widget.AutoFitTextView", which is greater than the 23 character limit specified in the [Android Docs](http://developer.android.com/reference/android/util/Log.html#isLoggable%28java.lang.String, int%29).
If I use AutofitTextView inside a TextSwitcher the text won't be resized.
CustomViewFactory.java:
...
@Override
public View makeView() {
AutofitTextView textView = (AutofitTextView) mActivity.getLayoutInflater().inflate(R.layout.text_view_output, mRoot, false);
return textView;
}
...
text_view_output.xml:
<?xml version="1.0" encoding="utf-8"?>
<me.grantland.widget.AutofitTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:lines="1"
android:gravity="center">
</me.grantland.widget.AutofitTextView>
activity_main.xml
...
<RelativeLayout
android:id="@+id/relativeLayoutContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="end">
...
<TextSwitcher
android:id="@+id/textSwitcherOutput"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
...
Error:
The method getMaxLines() of type AutofitTextView must override or implement a supertype method
@OverRide
public int getMaxLines() {
return mMaxLines;
}
Could you specify the license for View? Thanks.
There seems to be some problem with ICS:
Launching the sample application and performing the autofit on a new text the application crashes.
This is the logcat of the crash:
06-30 21:55:17.395: I/dalvikvm(1325): threadid=3: reacting to signal 3
06-30 21:55:17.505: I/dalvikvm(1325): Wrote stack traces to '/data/anr/traces.txt'
06-30 21:55:17.615: D/me.grantland.widget.AutoFitTextView(1325): low=0.0 high=50.0 mid=25.0 target=320.0 width=320.0
06-30 21:55:17.635: D/me.grantland.widget.AutoFitTextView(1325): low=0.0 high=50.0 mid=25.0 target=320.0 width=320.0
06-30 21:55:17.666: D/me.grantland.widget.AutoFitTextView(1325): low=0.0 high=50.0 mid=25.0 target=320.0 width=320.0
06-30 21:55:17.676: D/gralloc_goldfish(1325): Emulator without GPU emulation detected.
06-30 21:55:20.825: D/me.grantland.widget.AutoFitTextView(1325): low=0.0 high=50.0 mid=25.0 target=320.0 width=362.0
06-30 21:55:20.825: D/me.grantland.widget.AutoFitTextView(1325): low=0.0 high=24.0 mid=12.0 target=320.0 width=175.0
06-30 21:55:20.835: D/me.grantland.widget.AutoFitTextView(1325): low=13.0 high=24.0 mid=18.5 target=320.0 width=282.0
06-30 21:55:20.835: D/me.grantland.widget.AutoFitTextView(1325): low=19.5 high=24.0 mid=21.75 target=320.0 width=325.0
06-30 21:55:20.835: D/me.grantland.widget.AutoFitTextView(1325): low=19.5 high=20.75 mid=20.125 target=320.0 width=285.0
06-30 21:55:20.846: D/me.grantland.widget.AutoFitTextView(1325): low=21.125 high=20.75 mid=20.9375 target=320.0 width=307.0
06-30 21:55:20.846: D/me.grantland.widget.AutoFitTextView(1325): low=21.9375 high=20.75 mid=21.34375 target=320.0 width=307.0
06-30 21:55:20.855: D/me.grantland.widget.AutoFitTextView(1325): low=22.34375 high=20.75 mid=21.546875 target=320.0 width=325.0
06-30 21:55:20.865: D/me.grantland.widget.AutoFitTextView(1325): low=22.34375 high=20.546875 mid=21.445313 target=320.0 width=307.0
06-30 21:55:20.875: D/me.grantland.widget.AutoFitTextView(1325): low=22.445313 high=20.546875 mid=21.496094 target=320.0 width=307.0
06-30 21:55:20.875: D/me.grantland.widget.AutoFitTextView(1325): low=22.496094 high=20.546875 mid=21.521484 target=320.0 width=325.0
06-30 21:55:20.885: D/me.grantland.widget.AutoFitTextView(1325): low=22.496094 high=20.521484 mid=21.50879 target=320.0 width=325.0
06-30 21:55:20.885: D/me.grantland.widget.AutoFitTextView(1325): low=22.496094 high=20.50879 mid=21.502441 target=320.0 width=325.0
06-30 21:55:20.885: D/me.grantland.widget.AutoFitTextView(1325): low=22.496094 high=20.502441 mid=21.499268 target=320.0 width=307.0
06-30 21:55:20.895: D/me.grantland.widget.AutoFitTextView(1325): low=22.499268 high=20.502441 mid=21.500854 target=320.0 width=325.0
06-30 21:55:20.895: D/me.grantland.widget.AutoFitTextView(1325): low=22.499268 high=20.500854 mid=21.500061 target=320.0 width=325.0
06-30 21:55:20.905: D/me.grantland.widget.AutoFitTextView(1325): low=22.499268 high=20.500061 mid=21.499664 target=320.0 width=307.0
06-30 21:55:20.905: D/me.grantland.widget.AutoFitTextView(1325): low=22.499664 high=20.500061 mid=21.499863 target=320.0 width=307.0
06-30 21:55:20.915: D/me.grantland.widget.AutoFitTextView(1325): low=22.499863 high=20.500061 mid=21.499962 target=320.0 width=307.0
06-30 21:55:20.915: D/me.grantland.widget.AutoFitTextView(1325): low=22.499962 high=20.500061 mid=21.500011 target=320.0 width=325.0
06-30 21:55:20.915: D/me.grantland.widget.AutoFitTextView(1325): low=22.499962 high=20.500011 mid=21.499987 target=320.0 width=307.0
06-30 21:55:20.925: D/me.grantland.widget.AutoFitTextView(1325): low=22.499987 high=20.500011 mid=21.5 target=320.0 width=325.0
06-30 21:55:20.925: D/me.grantland.widget.AutoFitTextView(1325): low=22.499987 high=20.5 mid=21.499992 target=320.0 width=307.0
06-30 21:55:20.925: D/me.grantland.widget.AutoFitTextView(1325): low=22.499992 high=20.5 mid=21.499996 target=320.0 width=307.0
06-30 21:55:20.935: D/me.grantland.widget.AutoFitTextView(1325): low=22.499996 high=20.5 mid=21.499998 target=320.0 width=307.0
06-30 21:55:20.935: D/me.grantland.widget.AutoFitTextView(1325): low=22.499998 high=20.5 mid=21.5 target=320.0 width=325.0
06-30 21:55:20.935: D/me.grantland.widget.AutoFitTextView(1325): low=22.499998 high=20.5 mid=21.5 target=320.0 width=325.0
06-30 21:55:20.935: D/me.grantland.widget.AutoFitTextView(1325): low=22.499998 high=20.5 mid=21.5 target=320.0 width=325.0
06-30 21:55:20.945: D/me.grantland.widget.AutoFitTextView(1325): low=22.499998 high=20.5 mid=21.5 target=320.0 width=325.0
[... a lot more of these lines...]
06-30 21:55:20.945: D/me.grantland.widget.AutoFitTextView(1325): low=22.499998 high=20.5 mid=21.5 target=320.0 width=325.0
06-30 21:55:21.115: I/dalvikvm(1325): threadid=1: stack overflow on call to Ljava/lang/Math;.ceil:DD
06-30 21:55:21.115: I/dalvikvm(1325): method requires 8+20+0=28 bytes, fp is 0x44b93310 (16 left)
06-30 21:55:21.115: I/dalvikvm(1325): expanding stack end (0x44b93300 to 0x44b93000)
06-30 21:55:21.115: I/dalvikvm(1325): Shrank stack (to 0x44b93300, curFrame is 0x44b96ec8)
06-30 21:55:21.115: D/AndroidRuntime(1325): Shutting down VM
06-30 21:55:21.115: W/dalvikvm(1325): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
06-30 21:55:21.225: D/dalvikvm(1325): GC_CONCURRENT freed 255K, 6% free 6750K/7111K, paused 3ms+3ms
06-30 21:55:21.265: E/AndroidRuntime(1325): FATAL EXCEPTION: main
06-30 21:55:21.265: E/AndroidRuntime(1325): java.lang.StackOverflowError
06-30 21:55:21.265: E/AndroidRuntime(1325): at java.lang.RealToString.longDigitGenerator(RealToString.java:269)
06-30 21:55:21.265: E/AndroidRuntime(1325): at java.lang.RealToString.convertFloat(RealToString.java:177)
06-30 21:55:21.265: E/AndroidRuntime(1325): at java.lang.RealToString.appendFloat(RealToString.java:130)
06-30 21:55:21.265: E/AndroidRuntime(1325): at java.lang.StringBuilder.append(StringBuilder.java:169)
06-30 21:55:21.265: E/AndroidRuntime(1325): at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:117)
06-30 21:55:21.265: E/AndroidRuntime(1325): at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:120)
06-30 21:55:21.265: E/AndroidRuntime(1325): at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:120)
06-30 21:55:21.265: E/AndroidRuntime(1325): at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:120)
06-30 21:55:21.265: E/AndroidRuntime(1325): at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:120)
06-30 21:55:21.265: E/AndroidRuntime(1325): at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:120)
06-30 21:55:21.265: E/AndroidRuntime(1325): at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:120)
[... a lot more of these lines...]
06-30 21:55:21.265: E/AndroidRuntime(1325): at me.grantland.widget.AutofitTextView.getTextSize(AutofitTextView.java:120)
06-30 21:55:21.265: E/AndroidRuntime(1325): at me.gran
Autofittextview was working fine till i tried to implement something;
I deleted everything i made, the code is fully same the time it was working.
Please help
04-21 01:54:03.287 7118-7118/com.gor.hocam E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gor.hocam, PID: 7118
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gor.hocam/com.gor.hocam.MainActivity}: android.view.InflateException: Binary XML file line #56: Error inflating class me.grantland.widget.AutofitTextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5139)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #56: Error inflating class me.grantland.widget.AutofitTextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)
at android.app.Activity.setContentView(Activity.java:1929)
at com.gor.hocam.MainActivity.onCreate(MainActivity.java:111)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5139)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "me.grantland.widget.AutofitTextView" on path: DexPathList[[zip file "/data/app/com.gor.hocam-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.gor.hocam-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:559)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)
at android.app.Activity.setContentView(Activity.java:1929)
at com.gor.hocam.MainActivity.onCreate(MainActivity.java:111)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5139)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Is there a way to unlink a TextView
with this library? I have to find the smallest textSize
for a particular TextView
and store it, and then set a very new textSize
to that TextView
�.
However, the TextView's
text gets resized, no matter the new textSize
I've set. I have also tried to reinitialize the TextView
via the findViewById
method.
I am using regular TextView
in my xml, and then AutoFitHelper.create(myTextView)
in code.
There must be a workaround here.
Hello.
Is there a chance, that you will reduce minSdkVersion
?
To 10
for example.
Regards.
On some cases, the letter of one word goes to the next line.
Here's a sample case:
<me.grantland.widget.AutofitTextView
android:id="@+id/output_autofit"
android:layout_width="286dp"
android:layout_height="305dp"
android:maxLines="3"
android:text="content text sample" />
mAutofitOutput = (AutofitTextView) findViewById(R.id.output_autofit);
mAutofitOutput.setMaxTextSize(1000);
BTW, there is no "maxTextSize" attribute, so I had to do it via code instead.
The result (modified the sample) :
Not only that, but for the same case, when increasing the width of the textView, the text itself gets truncated. Here's what happens when I set the width to match_parent :
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.