Comments (8)
Just use what I wrote there:
private static void runJustBeforeBeingDrawn(final View view, final Runnable runnable)
{
final ViewTreeObserver vto = view.getViewTreeObserver();
final OnPreDrawListener preDrawListener = new OnPreDrawListener()
{
@Override
public boolean onPreDraw()
{
Log.d(App.APPLICATION_TAG, CLASS_TAG + "onpredraw");
runnable.run();
final ViewTreeObserver vto = view.getViewTreeObserver();
vto.removeOnPreDrawListener(this);
return true;
}
};
vto.addOnPreDrawListener(preDrawListener);
}
alternatively , you can use addOnGlobalLayoutListener instead of addOnPreDrawListener if you wish.
from autofittextview.
Thanks a lot AndroidDeveloperLB, it works now.
from autofittextview.
I think this is the reason:
http://stackoverflow.com/q/10923321/878126
and solution:
http://stackoverflow.com/a/10923514/878126
You basically get the width&height of the container of the view that you create, before you give it a chance to know what size it should be.
Instead of this, either use the function in the solution, or just put the AutoResizeTextView inside the XML file, and let it all be automatically for you.
The reason I wrote it in code was to demonstrate that it can adjust to various sizes.
from autofittextview.
In order to check that I'm correct, check the value that you get for :
int width=...
from autofittextview.
maybe you can try to post a new delayed runnable to execute show_auto_resized_text()
@hakan6000 you said you are learning so I am posting source here for your help but this may or may not help you for this issue...but sometimes allowing a delay does work for first run issues....(not the ideal fix but it can help in a pinch sometimes)
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 100ms
}
}, 100);
See -> http://stackoverflow.com/a/9166354/1815624
from autofittextview.
No, time handling isn't needed. plus there will be a time the user won't see it well.
from autofittextview.
@hakan6000 AndroidDeveloperLB is correct...
from autofittextview.
@hakan6000 You're welcomed. You are also invited to try my other repos. Recent one that I've made is a tool to convert your app's images into WebP:
https://github.com/AndroidDeveloperLB/WebpifyYourAndroidApp/
from autofittextview.
Related Issues (20)
- Size gets crazy inside a cardView in recyclerView HOT 18
- Crashing. HOT 2
- AutoResizeTextView doesn't wrap content when has new line character in the string ('\n') HOT 8
- Setting maxlines and ellipsize doesn't ellipsize the end of the TextView HOT 2
- Remove AllowBackup tag from library manifest HOT 1
- Set text size method clarification HOT 6
- StringIndexOutOfBoundsException when trying to load String that ends with \n HOT 1
- AutoResizeTextView doesn't scale property if I set custom LetterSpacing HOT 3
- Not working if it has weblink from server HOT 11
- Support for widget HOT 1
- when i add onclick attribute, application crashes HOT 16
- Dosen't work with Chinese multiline sentence HOT 1
- Android Developer
- 你库升级一时爽 HOT 1
- Hebrew words are cut in the bottom of last line HOT 1
- License is missing copyright HOT 5
- This library failed if only emojies text HOT 1
- [email protected]
- https://support.chaturbate.com/hc/en-us/articles/360037125892-Buying-tokens HOT 1
- Mappe
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autofittextview.