Android realizes customized bullet screen effect

1、 Renderings

Let's take a look at the renderings first~~

2、 Implementation principle scheme

1. Customize ViewGroup xcdanmuview and inherit relativelayout. Of course, you can also inherit the other three layout classes

2. Initialize several textviews (the item view of the bullet screen, take textview as an example here, of course, others ~), and then add them to the custom view through addview

3. It is added to xcdanmuview through addview. The position is in the coordinate. In order to achieve the effect of moving in from outside the screen

We also need to modify the position of the added textview to move from right to left. After addview, the position of the textview must be set outside the screen on the right

In this way, we use the onlayout () method to rearrange the childview and set the position

4. The bullet screen ItemView comes out randomly on the left or right. The movement adopts attribute animation to realize translation, moving from one end of the screen to the other end. When the animation is finished, the

The child is removed from xcdanmuview. And re create a bullet screen ItemView, add the view to xcdanmuview, and start the animation movement

5. This custom bullet screen view supports left to right and right to left directions, and supports custom settings for the maximum number of bullet screens displayed on the screen.

3、 Specific implementation of xcdanmuview with custom bullet screen effect

1. Data variables required for initialization

2. Initialize several bullet screen item views

3. Create bullet screen item view and add view to xcdanmuview

4. Reset the initial position of childview out of the screen

5. Moving effect of bullet screen item view

6. Turn on and off the barrage effect and the animation effect on the

4、 How to use this custom sideslip view control

It is very simple to use this custom view. The default effect of the control is from right to left. If you need to change the direction from left to right, just set the lower direction

5、 Summary

The above is all about realizing the custom barrage effect in Android. I hope the content of this article can be helpful to everyone when developing Android. If you have any questions, you can leave a message.

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