Question

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. 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. But if the Android version is below 4.0 it works well like in the video of the link.

Did anyone have a thoughts regards this issue?

Was it helpful?

Solution

UPDATE

A fix for this issue is to make the following change to 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. As an alternative, I implemented something similar to this using a HorizontalScrollView and centering using .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. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top