Comments (2)
I have the same error.
from android-marqueeview.
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.
To the developer, kindly revisit your logic to improve this otherwise beautiful piece of code.
Thanks
from android-marqueeview.
Related Issues (8)
- Exception when using android:layout_width="fill_parent" HOT 3
- Public constructor
- Adjusment of enrty point and end point of text HOT 1
- Not working on Android 7.0+
- goes back and forth
- Disable marquee effect when TextView is shorter than the container
- ScrollView cannot be cast to TextView Exception HOT 2
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 android-marqueeview.