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

问题描述

我想创建一个中水平显示图像a>.

Display the images horizontally in a ViewPager.

第2步:

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

此外,还有一些现成可用的开源窗口小部件,例如 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.

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

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

我会在ViewPager的PagerAdapter的instantiateItem()方法中在图像上使用此代码.这应该工作.或者,您可以在前面两个示例之一中尝试缩放动画方法.

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 21:28