Method for realizing multi page sliding switching and animation effect of viewpager by Android programming

This paper describes the method of realizing viewpager multi page sliding switching and animation effect by Android programming. Share with you for your reference, as follows:

1、 First, let's take a look at the rendering. This is the tab sliding effect of sina Weibo. We can gesture to slide, or click the header above to switch. In the same way,

The white bar will move under the corresponding page card head. This is an animation effect. The white bar slides slowly. Well, let's implement it.

2、 Before we start, we need to know a control, viewpager. It is a class of an add-on package in Google SDK, which can be used to switch between screens.

This add-on package is android-support-v4.jar, which will be provided to you in the final source code in the LIBS folder. Of course, you can also search the latest version from the Internet.

Once we find it, we need to add it to the project

3、 Let's make the interface first

The interface design is very simple. There are three headers in the first line, animation pictures in the second line, and page card content display in the third line.

We want to show three page cards, so we also need the interface design of the contents of the three page cards. Here we only set the background color to distinguish.

4、 The code part needs to be initialized

(1) First, the definition of variables

(2) Initialize header

I believe everyone will have no problem after reading. Click the page to display the contents of the card on the page.

(3) Initialize page card content area

We load three page card interfaces into them, and the first page card is displayed by default. Here we also need to implement an adapter.

Here we realize the loading and unloading of each page card

(3) Initialize animation

The offset of the animation movement is calculated according to the resolution of the screen and the width of the picture

Realize page card switching monitoring

5、 After finishing work, come and see your achievements

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