-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception: The child view of this MarqueeView must be a TextView instance. #8
Comments
I have the same error. |
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. 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! To the developer, kindly revisit your logic to improve this otherwise beautiful piece of code. Thanks |
java.lang.RuntimeException: The child view of this MarqueeView must be a TextView instance.
Here is my xml file:
The text was updated successfully, but these errors were encountered: