Android realizes pull-down parallax effect through overscrollby

Overscrollby realizes the pull-down parallax effect, and the effect diagram is as follows

Let's first analyze the use of the overscrollby method, which is a view method with a few parameters:

The general steps are as follows:

1. This is a listview as a whole, so you need to customize a listview. 2. Process the header layout file and add it to the customized listview in the form of headerview. 3. You need to obtain the initial height of the ImageView of the headerview and the height of the picture in the ImageView. Because these two heights will determine the range of the picture when it is pulled out, And the animation effect of the picture rebound after letting go. Corresponding to the acquisition of the width and height of the control, those interested can see this article on the acquisition of the width and height of the custom view. 4. Display more picture content by modifying the height value of layoutparams of ImageView in the overscrollby method. 5. Process action in the ontouchevent method_ Up event to make ImageView have rebound animation effect. Here are two methods: attribute animation and custom animation

OK, let's first look at the layout file of headerview:

Nothing special is that an ImageView is set through Src. The only thing to do here is to set the scaletype attribute. I set centercrop here to intercept the image from the smallest edge. Because the selected image is higher than the width, the full width will be retained during clipping. The center clipping is shown in the following figure:

Custom listview code, the overall code is relatively short

Look at custom animation:

Mainactivity test class:

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