HoritzontalScrollView或卡鲁塞尔? [英] HoritzontalScrollView or Carrousel?

查看:271
本文介绍了HoritzontalScrollView或卡鲁塞尔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 Horizo​​ntalScrollView ,但在它的一些效果,像这样的<一个href="http://25.media.tumblr.com/0a46e97269c9b8a269f5df1c2e813556/tumblr_melwhjYQby1r6rtzuo6_r1_1280.png">example,或本另一个例子。问题是,我不知道有多少项目我将不得不使用;我得到的的ImageView 从API,所以它应该是动态的。我怎么能作出这样的效果,如果它的选择就变得更大了与的TextView 下面?我发现最近的例子SO是<一个href="http://stackoverflow.com/questions/32310390/how-to-create-horizontal-scrollview-with-zoom-on-selected-item">here.这正是我需要的,但我已经测试过了答案给定的,并没有为我工作......但问题的形象正是我想要的。任何人都可以指导我做到这一点?

I want to create a HorizontalScrollView, but with some "effects" in it, like this example, or this other example. The thing is that I don't know how many items I'll have to use; I get the ImageView from an API so it should be dynamic. How can I make that effect that if it's selected it becomes bigger with the TextView below? The closest example I found on SO is here. That's exactly what I need, but I've tested the answer given and it doesn't work for me ... but the image from the question is exactly what I want. Can anyone guide me to do this?

比方说,我会和测试5 的ImageView 仅用于测试,这样一个例子来如何添加这些 ImageView的动态将是一件好事,我也是如此。

Let's say I'll test it with 5 ImageView ONLY FOR TESTING, so an example to how to add those ImageView dynamically would be good for me as well.

另一个例子是 Snapchat应用,但不同的是,我想补充的选择一样可以做些效果它更大的什么的。

Another example would be Snapchat APP but the difference is that I would like to add some effect on the selected like make it bigger or something.

我想获得一个例子,如何做这样一个自定义Horizo​​ntalScrollView与布局(适配器)和最重要的,如果有可能的效应添加到点击了其中一个,而我想要的适配器,因为我需要点击获取课程的项目。我想我应该用一个RecycleView作为@UncaughtException对我说,因为我不知道我会多么的图像获取和我得把我的应用程序中的事情,所以我觉得这是解决方案。

I would like to get an example to how to do like a custom HorizontalScrollView with a Layout (adapter) and the most important if it's possible add an efect to the clicked one, and I want the adapter because I'll need to get the item clicked of course. The thing that I think I should use a RecycleView as @UncaughtException said to me because I don't know how much images I'll get and I'll have to put on my APP so I think this is the solution.

这将是之间 Snapchat HoritzontalScrollView 和的从这个形象太问题

推荐答案

第1步:

水平在 显示图像ViewPager

第二步:

应用 ScaleAnimation 类点击的项目放大就可以了。这可以在 ViewPager PagerAdapter instantiateItem()方法来实现code>。

Apply the ScaleAnimation class to the clicked item to zoom in on it. This can be done in the instantiateItem() method of the ViewPager's PagerAdapter.

另外,还有一些可用如 的CoverFlow FancyCoverFlow 。你可能想看看源$ C ​​$ C,看看他们是如何工作的。

Also, there are some ready-to-use open source widgets available like CoverFlow and FancyCoverFlow. You might want to check out the source code to see how they work.

编辑:

首先,关于你如何处理未知数量的图像的问题,您应该认识到,在所有这些部件(的ListView 的GridView ViewPager 等),对象从API到来的数目总是未知在第一,即然后API响应被接收时,它成为已知。所以,如果你第一次实施 ViewPager 以正常的方式,你会看到这是如何处理的。基本上,你必须使用适配器和模型对象来填充 ViewPager 的ListView 。 API响应将是无论是JSON或XML和解析后,你就会知道物品的确切人数。

Firstly, regarding your question of how to handle an unknown number of images, you should realize that in all such widgets (ListView, GridView, ViewPager etc.), the number of objects coming from the API is always unknown at first, i.e. it becomes known when then API response is received. So if you first implement a ViewPager in the normal way, you will see how this is handled. Basically you have to use an Adapter and a model object to populate the ViewPager or ListView. The API response will be either JSON or XML, and after parsing it, you will know the exact number of items.

所以,我认为你应该从第一实施 ViewPager 以正常的方式。有任何可用于该号码的例子。两个有趣的是这个和的这个。他们是有趣的情况,因为它们也含有例如$ C $如何放大图像℃。

So I think you should start with first implementing a ViewPager in the normal way. There are any number of examples available for this. Two interesting ones are this one and this one. They are interesting for your case because they also contain example code of how to enlarge the image.

现在来了第二个问题:我们如何放大图像。要做到这一点,一种方法是使用 ScaleAnimation 类。例如,假设你想100%放大图像围绕中心:

Now coming to the second problem: how do we enlarge the image. To do this, one way is to use the ScaleAnimation class. For example, say you want to enlarge an image by 100% around its center:

ScaleAnimation scaleAnimation =  new ScaleAnimation(1.0f, 1.5f,
                                                    1.0f, 1.5f,
                                                        Animation.RELATIVE_TO_SELF, 0.5f,
                                                        Animation.RELATIVE_TO_SELF, 0.5f);

scaleAnimation.setDuration(200);
scaleAnimation.setInterpolator(new AccelerateDecelerateInterpolator());

imageView.startAnimation(scaleAnimation);

我会用这个code中的 instantiateItem()方法,在图像上的 ViewPager 小号 PagerAdapter 。这应该工作。或者你可以尝试缩放动画的方式在两个previous的例子之一。

I would use this code on the image in the instantiateItem() method of the ViewPager's PagerAdapter. This should work. Or you can try the zoom animation approach in one of the two previous examples.

我怕你必须尝试创建使用这些例子作为指导工作的项目。然后,我们可以进一步讨论您所面临的任何其他问题。我敢肯定,这可以很容易做的,我知道你可以做到这一点。最好...

I'm afraid you'll have to try to create a working project using these examples as a guide. Then we can further discuss any other problems you face. I'm sure that this can be done quite easily, and I know you can do it. Best ...

编辑2:

根据您所提供的两个例子,你见过?这就是你要找的内容?而它带给你更接近解决问题?

As per the two examples that you have given, have you seen this and this? Is that what you're looking for ? And does it bring you any closer to solving the problem ?

这篇关于HoritzontalScrollView或卡鲁塞尔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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