Android implements listview with parallax effect

What is the parallax effect?

The so-called parallax effect is very common in web design and mobile applications. We can find it on some major platforms, from Windows Phone to IOS and even Android. According to Wikipedia, parallax scrolling is a special scrolling technology in computer graphics. Here, the camera moves the background image slower than the foreground image, resulting in the illusion of visual depth.

So what is parallax effect? Let's look at the renderings:

We can see that the headerview of the listview will become larger with the sliding of the listview, and the pictures in the headerview will have a zoom effect. These can be achieved using attribute animation. Next, let's do it!

First, customize several attributes, which can be used later:

Then create a zoomlistview class, which inherits from listview:

To follow the prescribed order, set the initial value of the custom property, then call initView (), then look at the initView () method:

It can be seen that in initview (), we created headerview and added it to the header of listview. Setdrawableid (int ID) is used to set relevant pictures for headerview.

The following is the main implementation code of parallax effect:

We override the overscrollby () method. When delta is less than 0 (that is, the listview has reached the top, but the user gesture is still pulled down), we dynamically set the height of the headerview and the scale value of the headerview. In this way, the headerview can be raised and the picture can be enlarged.

The next problem to consider is to return to the original appearance when the user releases his finger. Therefore, we should implement relevant operations in ontouchevent (motionevent EV):

The above code is simply in action_ When up, start two attribute animations. One is to restore the headerview height to the original value, and the other is to restore the headerview scale to 1F. I believe everyone can understand.

summary

The above is the whole content of this article. I hope the content of this article can be helpful to Android developers. 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
分享
二维码
< <上一篇
下一篇>>