AutoScrollTextView | android 上下滚动播放与走马灯效果结合
kandi X-RAY | AutoScrollTextView Summary
kandi X-RAY | AutoScrollTextView Summary
AutoScrollTextView
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Called when the activity is created
- Init marguee
- Initialize Marguee text
- Stop the text view
- Start scroll
- Stops the future
- Resets the scroll position
- Implement onDraw method
- Calculate the text width
- On createView
- Set up widgets
- Makes the view
- Set the marquee listener
- Sets the text to the next view
- Set the current text to the next view
- Adds a view to the adapter
- Stop scrolling
- Initializes the view
- Creates a text view with the accent color
- Start scrolling
- Initializes the UI
- Returns class name of accessibility class
AutoScrollTextView Key Features
AutoScrollTextView Examples and Code Snippets
Copyright 2016 haohaohu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless r
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.ronghao:AutoScrollTextView:1.0.3'
}
@Override
public MarqueeTextView makeTextView() {
MarqueeTextView textView = new MarqueeTextView(getContext());
textView.setTextColor(getResources().getColor(R.color.colorAccent));
return textView;
}
Community Discussions
Trending Discussions on AutoScrollTextView
QUESTION
First I describe the context, i.e. what I'm trying to do
Second I explain you in which cases I encounter the bug and what is it (it's the current behavior)
Third, I explain you the expected behavior
Then I explain you how to reproduce the bug
Finally I show you the minimal and executable code that can lead to the bug
I am using the widget AutoScrollTextView
available between others in the API https://github.com/ronghao/AutoScrollTextView. AutoScrollTextView
is a TextView
that can automatically autoscroll vertically and moreover, if the text is too long, horizontally. So an AutoScrollTextView
can contain at least one text to be automatically scrolled (see the illustration in the GitHub repository).
- If I use one
AutoScrollTextView
in the main activity, I don't see any bug. If I use it in the fragment of the main activity, I think it would be the case too (I didn't test it). - If I use one
AutoScrollTextView
in each of at least two fragments of aViewPager
(2 instances of this same fragment class are used for theViewpager
), with at least one text to be automatically scrolled by eachAutoScrollTextView
, the app crashes with the following error (NB: thisViewPager
belongs to the main activity):
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.myapplication, PID: 2814 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.sendAccessibilityEventUnchecked(android.view.accessibility.AccessibilityEvent)' on a null object reference at android.view.ViewRootImpl$SendWindowContentChangedAccessibilityEvent.run(ViewRootImpl.java:9304) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6944) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
The error, however, is difficult to trigger:
- Sometimes, it's triggered as soon as the fragment of the main activity is started
- Sometimes, there is a random delay before it's triggered in the fragment of the main activity
- Sometimes, maybe it's not triggered (or I close the app before it would)
As you can see, there isn't any indication of the line that causes this crash.
What I've done to debugI have taken the library, and isolated the minimal part of it that lead to this bug.
I have set up the minimal executable app with only the main activity, the
ViewPager
, and the fragment (2 instances of this same fragment class are used for theViewpager
).I have set up this minimal executable app with the isolated part of the library. You will find the sources below (even if there are "many" files, each one has been minimalized and contains only the strict minimal lines in order to make you able to reproduce the bug). Also: with the sources I give you, it's totally normal that you don't see text scrolling (nor text at all). It's because I've completely isolated the part of the API that triggers the bug, and the scrolling text wasn't related to this error, so it's not part of my isolated sources.
I have tried to use Android's
Timer
instead of anHandler
but the error still occurres.MarqueeTextView::scrollTo(currentScrollPos, 0);
seems to trigger this error.
Normally, the app of course should not crash. In other words, there shouldn't be any triggered error (especially the one I've quoted above). With the sources I give you, it's totally normal that you don't see text scrolling (nor text at all). It's because I've completely isolated the part of the API that triggers the bug, and the scrolling text wasn't related to this error, so it's not part of my isolated sources.
How to reproduce this bugBelow, I provide you all the minimal and executable sources you need (even if there are "many" files, each one has been minimalized and contains only the strict minimal lines in order to make you able to reproduce the bug). After having created the corresponding files and copy/paste these sources in them, run this minimal and executable app several times. Even if the error will or won't be shown for each run, normally you would see it at least one time after 5 runs max. You can use your smartphone to test this app, or maybe an Android Studio's emulator (but I didn't test on an emulator).
NB: with the sources I give you, it's totally normal that you don't see text scrolling (nor text at all). It's because I've completely isolated the part of the API that triggers the bug, and the scrolling text wasn't related to this error, so it's not part of my isolated sources.
My questionCould you tell me why this bug occures (I was unable to debug it) and why it seems so random? How could I correct it?
Minimal and executable app's sources Short presentationFirst, I will give you the sources of the isolated part of the library
Then, I will give you the sources of the app with the
ViewPager
, etc.Even if there are "many" files, each one has been minimalized and contains only the strict minimal lines in order to make you able to reproduce the bug. With the sources I give you, it's totally normal that you don't see text scrolling (nor text at all). It's because I've completely isolated the part of the API that triggers the bug, and the scrolling text wasn't related to this error, so it's not part of my isolated sources.
ANSWER
Answered 2020-Apr-07 at 09:45I think I have solved the problem by using runOnUiThread
in the method MarqueeTextView::TimerTask::run
. Since this change, I didn't see any bug. But I still don't know why this bug occurred, and why this modification solved it (I know it's better to use runOnUiThread
in this situation since scrollTo
is used, but I don't know what is the relationship between this call and the bug). If someone could comment my answer, to explain me, please :-) .
You can compare the changes (presented below) with the original file in my question.
So the only changes I've made are contained in the following file (com.example.myapplication.libs.autoscrolling_text_view.MarqueeTextView):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install AutoScrollTextView
You can use AutoScrollTextView like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the AutoScrollTextView component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page