如何添加Parallex影响到列表中的Andr​​oid项目 [英] How to add Parallex Effects to List Item in android

查看:203
本文介绍了如何添加Parallex影响到列表中的Andr​​oid项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序,仅显示图像列表中的列表视图。现在,我想补充parallex效果列表项,同时滚动列表视图。我刚才只执行列表视图。任何帮助鸭preciated .........

I have an listview in my app, which displays list of images only. Now I want to add parallex effect for list items while scrolling the listview. I just now implemented listview only. Any Help Appreciated.........

推荐答案

在简单地说,你需要一个标题设置为您的ListView。这头将包含图像要上应用视差以及原来应该通过内容(通常是一个经典的ListView头,但它可能也有一些看起来像你的列表中的任何元素)。

In a nutshell, you need to set a header to your ListView. This header will contain the image you want to apply a parallax on as well as the content that should go over (it usually is a classic ListView header but it could as well be something that looks like any element of your list).

第二个主要的事情是增加一个 ScrollListener 你的的ListView ,并创建一个自定义的ImageView的(它覆盖的ImageView )即能收到您的名单多少滚动。在 onScroll 回调,可以检索列表的第一个元素,如果它是可见的,做一个共达()它并将其发送到您的自定义ImageView的。

The second main thing is to add a ScrollListener to your ListView, and create a custom ImageView (which overrides ImageView) that is able to receive how much your list has scrolled. In the onScroll callback, you can retrieve the first element of the list if it is visible, do a getTop() on it and send it to your custom ImageView.

您现在有知道它是屏幕甚至当你的清单上滚动的ImageView的。所有你需要知道的是把你的观点的Y(带有 canvas.translate() view.translate()这取决于SDK版本你的工作)。

You now have an ImageView that knows where it is on the screen even when your List scrolls. All you need to know is to translate the Y of your view (with either canvas.translate() or view.translate() depending on which SDK version you're working on).

我不认为它需要更多的时间比整合图书馆和它的伟大工程!

I don't think it takes much more time than integrating a library and it works great!

这篇关于如何添加Parallex影响到列表中的Andr​​oid项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆