Android development uses a custom view to realize the parallax effect function of listview drop-down

This example describes how Android development uses a custom view to realize the parallax effect function of listview drop-down. Share with you for your reference, as follows:

1、 Overview:

Now, flow type apps such as wechat circle of friends, QQ space and microblog personal display all have the shadow of parallax effect.

As shown in the figure: the drop-down picture will have the effect of pulling up the picture. After letting go, the picture will bounce back to its original place:

So how do we achieve it?

1) Override listview control: 2) override the overscrollby method in it; 3) execute value animation after letting go

2、 Specific implementation:

1. Create parallelistview custom listview

2) Add to layout:

3) Generate home page and fill in data:

4) Create header layout:

Set the picture to scaletype = "centercrop" mode

Description of other modes:

5) Find the header layout in the home page and add it to the listview

3、 Function realization:

1. We can basically see the effect now, but we have to drag the picture, which is to implement this method overscrollby

Because the drag is in the y-axis direction, you just need to print the parameters in the y-axis direction

Get the drop-down data: deltay = - 3 scrollx = 0 scrollrange = 0 maxoverscrolly = 0 istouchevent = true

Get data pull-up: deltay = 4 scrollx = 0 scrollrange = 0 maxoverscrolly = 0 istouchevent = true

2. If it is a drop-down, we assign the value to the header, but how do we get the height?

1) Initialize the image in the home page, and then set it to the parallalistview

2) Create the method setparallelaimage in the parallellistview

The result is: height = 0, measureheight = 0, instrinsicheight = 732

Why: because the picture is not initialized at this time

How do we get the height?

Remember that there is a method called iv.getviewtreeobserver (), so we get a high degree of recognition in the listening event of this method

At this time, the height obtained is height = 240, measureheight = 240, instrinsicheight = 732

3) Assign the value to the picture to achieve the stretching effect

3. After releasing the hand, the picture rebounds. This function is realized in ontouchevent:

4. Animation implementation:

4、 Source code download:

Click here to download the complete example code.

More readers interested in Android related content can view the special topics of this site: Android control usage summary, Android development introduction and advanced tutorial, Android view skill summary, activity operation skill summary of Android programming, Android database operation skill summary and Android resource operation skill summary

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