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

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

问题描述

我想创建一个HorizontalScrollView,但是其中包含一些效果",例如其他示例.问题是我不知道要用多少个物品.我从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 仅用于测试进行测试,因此如何动态添加这些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 推荐答案

步骤1:

ViewPager 中水平显示图像a>.

Display the images horizontally in a ViewPager.

第2步:

ScaleAnimation 类应用于被点击的要放大的项目.可以在ViewPagerPagerAdapterinstantiateItem()方法中完成.

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

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 ...

根据您给出的两个示例,您是否看到过?那是您要找的东西吗?它将使您更接近解决问题吗?

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天全站免登陆