简体   繁体   English

Android Cover Flow

[英]Android Cover Flow

I'm using a cover flow in my Android App with this tutorial link http://www.inter-fuser.com/2010/01/android-coverflow-widget.html and I already use it well. 我在带有本教程链接http://www.inter-fuser.com/2010/01/android-coverflow-widget.html的 Android应用中使用封面流程,并且我已经很好地使用了它。 But my problem is when the Android version is 4.1 the cover flow semms not working well, because the images is not being centered or aligning well after choosing an image. 但是我的问题是,当Android版本为4.1时,覆盖流程无法正常运行,因为选择图像后图像无法居中或对齐良好。 But if the Android version is below 4.0 it works well like in the video of the link. 但是,如果Android版本低于4.0,则其效果就像链接视频中的一样。

Did anyone have a thoughts regards this issue? 有没有人对此问题有想法?

UPDATE UPDATE

A fix for this issue is to make the following change to getChildStaticTransformation(View child, Transformation t) 解决此问题的方法是对getChildStaticTransformation(View child, Transformation t)进行以下更改

protected boolean getChildStaticTransformation(View child, Transformation t) {
                child.invalidate(); // add this line
                final int childCenter = getCenterOfView(child);
                final int childWidth = child.getWidth();
                int rotationAngle = 0;

                t.clear();
                t.setTransformationType(Transformation.TYPE_MATRIX);

                if (childCenter == mCoveflowCenter) {
                        transformImageBitmap((ImageView) child, t, 0); 
                } else {
                        rotationAngle = (int) (((float) (mCoveflowCenter - childCenter) / childWidth) * mMaxRotationAngle);
                        if (Math.abs(rotationAngle) > mMaxRotationAngle) {
                                rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle
                                                : mMaxRotationAngle;
                        }   
                        transformImageBitmap((ImageView) child, t, rotationAngle);
                }   

                return true;
        }   

-- -

I had this same problem recently. 我最近有同样的问题。 This has to do with the Gallery having been deprecated. 这与不推荐使用Gallery有关 As an alternative, I implemented something similar to this using a HorizontalScrollView and centering using .scrollTo(). 或者,我使用Horizo​​ntalScrollView并使用.scrollTo()居中实现了与此类似的操作。 The problem with this solution is that scrollTo() aligns with the left side of the View and so you have to compute the middle y0urself. 该解决方案的问题在于,scrollTo()与View的左侧对齐,因此您必须计算中间的y0urself。 If the layout fills the screen you're going to have to apply padding to the left and right side of the view to force the selected element to the center. 如果布局填满了屏幕,则将必须在视图的左侧和右侧应用填充以将所选元素强制置于中心。

A word of caution. 请注意。 Horizontal scroll views don't have animatible scrolling so it's going to be a snap-to behavior. 水平滚动视图没有动画滚动,因此这将是一种快速操作。 You can get around this by scrolling using a timer but it's not a terribly elegant solution. 您可以通过使用计时器滚动来解决此问题,但这并不是一个非常优雅的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM