Method for realizing vertical scrolling effect of text caption similar to weather forecast by Android programming

This paper describes the method of Android programming to realize the vertical scrolling effect of text and caption similar to weather forecast. Share with you for your reference, as follows:

In many weather or news applications, we can see some subtitle scrolling effects. The simplest implementation is the marquee effect, which can be implemented with the properties provided by the system. More complex ones need to be implemented with custom controls. For example, let textview realize vertical scrolling. Here I want to talk about the subtitle effect of vertical scrolling, and the content is not only text, You can also add pictures or other elements. Without much nonsense, go directly to the renderings:

First, let's look at the implementation of the core:

At present, I rewrite Scrollview to provide several important methods:

The isscroled () method determines whether the current state is scrolling. Setscroled (boolean flag) sets the switch for scrolling. Setperiod (long period) sets the time from the beginning to the end of scrolling. Setspeed (long speed) sets the speed of scrolling

Here are some points to note:

1. Because it is a timed operation, it needs to be handled in the corresponding life cycle of the activity: when the interface is invisible, set setscroled (true) to turn on the scroll switch, and when it is invisible, setscroled (false) to turn off the switch

2. You can call setperiod (long period) and setspeed (long speed) to control the scrolling speed according to your needs

3. Because it is implemented by Scrollview, the content placed in the middle is the same as that of Scrollview. It can not only set text, but also add pictures and other elements to realize complex UI

4. Mixed text arrangement. At present, I haven't done detailed processing for this demo. The most important part is text processing, which needs to consider Chinese and English, full width and half angle, font size, paragraph processing, and calculate the corresponding character width and height for typesetting

The processing of images and other resources is relatively simple, mainly processing resolution and computing width and height

I will explain these parts in detail later

I wrote this demo temporarily. The UI and graphic mixing, including the specific scrolling part, are relatively simple. You can expand on the basis of this example and make the desired effect according to your needs:

The demo sample code can be downloaded here.

The following is the corresponding code:

First, customize the view:

MainActivity:

For more Android related content, readers who are interested can view the topics on this site: summary of Android service component usage skills, summary of activity operation skills of Android programming, summary of Android resource operation skills, summary of Android file operation skills, summary of Android SQLite database operation skills, summary of Android JSON format data operation skills Summary of Android database operation skills, introduction and advanced tutorial of Android development, summary of Android view skills and summary of Android control usage

I hope this article will help you in Android 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
分享
二维码
< <上一篇
下一篇>>