Great example of Android barrage effect

Many projects need to use the barrage effect, especially when playing the video, you need to display the barrage sent by others, including your own.

I tried to write this effect today.

The idea is to encapsulate the animation effect from right to left, font content, font size, bullet screen translation speed and other attributes together with textview into barrageitem, and bind the control effect and barrageitem to barrageview for display. The idea is still relatively simple. The bullet screen with expression is not considered here. I will keep updating it.

First look at the effect:

Project directory structure:

Next, define barrageitem.class: this class binds textview to the right to left animation effect, font content, font size, bullet screen translation speed and other attributes.

Then define barrageview. Since the font color, size and moving speed of the barrage are random, you need to define the maximum and minimum values to limit their range, and then set their values in this range by generating random numbers. In addition, you need to define the text content of the barrage. Here are some fixed values written directly.

BarrageView.class:

If the vertical position displayed by the barrage is random, the barrage will overlap in the vertical direction. Therefore, the vertical direction needs to be divided equally according to the maximum value of the barrage height according to the height, and then the barrage is randomly distributed in these specified vertical positions. This value is calculated in onwindowfocuschanged, because the height obtained through getmeasuredheight() of view in this method is not empty.

MainActivity.class:

The above is the source code of the barrage. In fact, I think the function of sending Barrage is missing here. I will update it in the future.

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
分享
二维码
< <上一篇
下一篇>>