Android implementation of custom rotation picture control example

To complete a rotating picture, the first thought should be to use viewpager. Viewpager already has the function of sliding. We just let it scroll by itself. Add the dot below. Therefore, our custom control is composed of viewpager and LinearLayout.

Direct first effect drawing:

Create a custom viewpager

Start with the complete code

Autoviewpager inherits from viewpager. We start a timer through timer.

Update the page every three seconds. In this way, you can have a self rolling effect.

Set adapter

To implement an infinite loop, just return the getcount () method in the adapter to infinity and directly return integer MAX_ Value is OK.

Complete adapter code:

We use generics here, because sometimes we may only pass in a URL collection or an object collection to facilitate expansion. The method of loading pictures is also an abstract method

Because the picture loading framework used by each app is different, the loading here is left to the app itself. When creating an adapter, just inherit the baseviewpageradapter here, override the loadimage (ImageView, t) method, and load the image here.

If you don't need a dot at the bottom, it's done here. When using, use it directly

replace

That's it. If you need a dot at the bottom, continue down

Add small dot mark

If small dots need to be added. In fact, it is to add another layer on the viewpager. We create a new view and inherit it to relativelayout

The complete code is as follows:

During initialization, create a viewpager and a LinearLayout (used to place small dots)

Then through addview (mviewpager); add to.

You need to prepare two pictures. Here you can draw with shape. You can view the use of Android shape

Initialize dot:

Update dot:

With small dots, use the following controls

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