Coder Social home page Coder Social logo

Comments (8)

AndroidDeveloperLB avatar AndroidDeveloperLB commented on August 17, 2024 1

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.

hakan6000 avatar hakan6000 commented on August 17, 2024 1

Thanks a lot AndroidDeveloperLB, it works now.

from autofittextview.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on August 17, 2024

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.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on August 17, 2024

In order to check that I'm correct, check the value that you get for :

int width=...

from autofittextview.

CrandellWS avatar CrandellWS commented on August 17, 2024

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.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on August 17, 2024

No, time handling isn't needed. plus there will be a time the user won't see it well.

from autofittextview.

CrandellWS avatar CrandellWS commented on August 17, 2024

@hakan6000 AndroidDeveloperLB is correct...

from autofittextview.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on August 17, 2024

@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)

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.