Android scroll bar advertising implementation code example

preface

Almost every online app will have a scroll bar advertisement. The scroll bar advertisement mainly exists in the form of text title. When you click to open an article, you can earn one million. After reading it, you can live a safe life. Such titles are attractive in the form of Title advertisement. Of course, you're kidding. Ha ha, after all, you want to make money, It's normal to take a few advertisements~~

Previously, in the project, it was required to make a rolling bar rotation display, that is, put several advertisements on the rolling bar for rotation. At first, I thought it was OK to use textswitcher or viewswitcher directly. Although this can also meet the demand, scroll bar advertising is used in several places in the project. It would be a bit wasteful to write the same set of code everywhere. Moreover, one of the design principles of the code is reuse, so a custom viewswitch is written for direct use. Of course, the custom is written, and the functional requirements should be improved. This viewswitcher enables us to customize the view on the scroll bar. Externally, you need to set the custom layout on the scroll bar and set the data source. Let's look at the renderings first.

Introduction to viewswitcher

Animate viewswitcher

The viewswitcher represents the view switching component and inherits the FrameLayout. It can stack multiple views and display only one component at a time. The viewswitcher supports the specified animation effect. When we customize the viewswitcher, when the program control switches from one view to another, we can override the following two methods to set the animation effect of component switching

Viewswitcher setting view

When setting the view method for the viewswitcher, the following method is called

The viewfactory is an interface with a makeview method. It is through this method that we construct and display it in the viewswitcher. Of course, when we customize the viewswitcher, we pass in a layout ID, so that we can freely set the display layout~

Example introduction

The implementation principle is still relatively simple. We can directly look at the code. Let's introduce the use of this control directly through the code

There are detailed notes inside. I believe you can understand them.

After reading the code, let's take a look at the external usage

External usage

External call

Layout of ItemView

Set entry animation

translate_ in.xml

Animate

translate_ out.xml

epilogue

The implementation is like this. The view layout is set externally. However, setting data for the controls in the view layout needs to be called inside. It depends on how you set the layout. This can be flexibly controlled inside according to the layout. The animation is also freely set outside. That's it

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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