Code Monkey home page Code Monkey logo

Comments (2)

morajabi avatar morajabi commented on July 20, 2024

I have the same error.

from android-marqueeview.

ArlonTM avatar ArlonTM commented on July 20, 2024

I was also getting that error... Then I decompiled the class and had a quick look at the source code; something seems to happen between removing the TextView (Line 201) and replacing with the ScrollView (Line 225), and the time your onLayout gets called again.

I notice you're testing the boolean variable "changed", which is passed as a parameter to the "onLayout" method, then you proceed to do further testing on the class type of the first child in the view tree, which is supposed to be a TextView, if there is indeed a TextView inside your custom MarqueeView, as the view is supposed to be used.

However, the timing of all that seems a bit off. Your "onLayout" gets called multiple times, even after the TextView has already been replaced by a ScrollView as your logic suggests; therefore, the test on the first child in the view tree fails, because it's no longer a TextView, but rather a ScrollView this time around.

Now, which circumstances do trigger a view's "onLayout"? That's the key to the mystery.
Anything that causes the view or its layout to invalidate itself and redraw, or to recalculate its dimensions, will eventually force a call on "onLayout"; that includes setting paddings, margins, width, height, relative or absolute positions, of the layout itself or any child within it.
So, a change in padding in the TextView contained in your custom MarqueeView will most certainly have the effect (undesired in this circumstance) of triggering the "onLayout" procedure.
But remember, not all those properties are handled at the same time, hence "onLayout" gets called after your routine has performed the replacement, thus not finding the TextView anymore.

I find, therefore, that a lot of assumptions were made, and not all angles were covered in the process of building this custom view. So, any change in the TextView's layout will eventually cause the whole structure to fall apart.

To those who are after a quick workaround to this problem, just remove any padding, margin on the TextView, leaving it to the bare required properties such as id, width, height, text, textColor, textSize, textStyle, ... I repeat, do not put anything that could possibly alter the layout!
Then, to enforce the single line, in order to keep the height unchanged, add the now deprecated "singleLine" property and set it to true. Any attempt to make this a multi-line TextView will also result in the same error.
Kindly check the snippet of code in the screenshot below.

snapshot

To the developer, kindly revisit your logic to improve this otherwise beautiful piece of code.

Thanks

from android-marqueeview.

Related Issues (8)

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.