Horizo​​ntalScrollView 还是 Carrousel? [英] HorizontalScrollView or Carrousel?

查看:16
本文介绍了Horizo​​ntalScrollView 还是 Carrousel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 Horizo​​ntalScrollView,但其中包含一些效果",例如 例子,或者这个其他例子.问题是我不知道我必须使用多少物品.我从 API 获取 ImageView 所以它应该是动态的.如果它被选中,我怎样才能使效果变得更大,下面的 TextView ?我在 SO 上找到的最接近的例子是 这里.这正是我所需要的,但我已经测试了给出的答案,但它对我不起作用......但问题中的图像正是我想要的.谁能指导我这样做?

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 ONLY FOR TESTING 对其进行测试,因此如何动态添加这些 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 APP 但不同的是我想添加一些对所选内容的影响,例如使其变大或其他.

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,最重要的是,如果可以为点击的效果添加效果,我想要适配器,因为我需要让项目点击当然.我认为我应该像@UncaughtException 那样使用 RecycleView 对我说的事情,因为我不知道我会得到多少图像并且我必须放在我的 APP 上,所以我认为这是解决方案.

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这张图片来自一个 SO 问题

推荐答案

第一步:

ViewPager<中水平显示图像/code>.

第 2 步:

应用 ScaleAnimation 分类到单击的项目以放大它.这可以在 ViewPagerPagerAdapterinstantiateItem() 方法中完成.

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.

此外,还有一些现成可用的开源小部件,例如 CoverFlowFancyCoverFlow.您可能想查看源代码以了解它们是如何工作的.

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.

首先,关于如何处理未知数量图像的问题,您应该意识到在所有此类小部件(ListViewGridViewViewPager 等),来自 API 的对象的数量一开始总是未知的,即当接收到 API 响应时它就变得已知了.因此,如果您首先以正常方式实现 ViewPager,您将看到它是如何处理的.基本上,您必须使用 Adapter 和模型对象来填充 ViewPagerListView.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.有许多可用的示例.两个有趣的是 这个这个.它们对您的情况很有趣,因为它们还包含如何放大图像的示例代码.

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);

我将在 ViewPagerPagerAdapterinstantiateItem() 方法中对图像使用此代码.这应该有效.或者您可以尝试前面两个示例之一中的缩放动画方法.

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 ?

这篇关于Horizo​​ntalScrollView 还是 Carrousel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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