Android imitation everyday beautiful songs auto scroll view

In the recent project, we want to make an effect similar to the automatic scrolling of beautiful songs every day. First of all, I think about what Android needs to scroll, that is, the scroller class, the combination of scrollto and scrollby, or the view. Layout () method, or using animation. However, it seems that rolling from the last line to the first line has the effect of rolling back, which is not a good solution. How can you forget the canvas that can draw events and everything. Well, now that you have found it, use this scheme! But the beautiful songs every day also have a manual sliding effect. It seems that this article has not been written. In that case, write it down yourself! Before realizing it, let's look at the beautiful effect every day:

text

Idea 1: get the sliding distance, then calculate how many rows have been slid, and then update the data. It doesn't seem to work well. Idea 2: we can see that it scrolls line by line, but the speed of scrolling lines is determined according to the speed of scrolling. In that case, as long as you scroll, scroll line by line for a certain time, and then determine the update interval according to the rolling speed.

Well, I've figured out how to implement it. Let's write the code now.

First write a class that inherits textview

VerticalScrollTextView.class

The custom view is basically like this. We can write some attributes to be defined in attrs, so we don't bother to write them here. The general idea is to draw the lyrics of the specified index line, then the lyrics of the upper line of index, and then the lyrics of the lower line of index. Then create a new thread and let it refresh the number of lyrics lines at regular intervals through handle. Then handle the number of touch scrolling lines in ontouchevent to obtain the current scrolling speed to determine an update interval. So as to realize the speed of touch scroll refresh. That's basically it. See the notes for others.

Take another look at the activity that initializes the data test:

VerticalScrollTextActivity.class

Simulate a song lyrics data, then setdatalist, and call updateui ().

Finally, look at the layout file

activity_ main.xml

Under the test, we can see the effect:

Download source code: Android imitates beautiful songs every day and automatically scrolls

The above is the whole content of this article. I hope it will help you learn Android Software Programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>