6

I'm using android coverflow, and it works fine on most of devices, but it seems that in Android 4.0.3 it does not put the center image back to the center once that you slide back and forth.

They remain "stuck" and under the wrong angle.

Did anyone had similar issues? What could cause this behavior?

So middle image on the attached image should be centered and not angled as it is.

CowerFlow Issue

Balkyto
  • 1,460
  • 4
  • 22
  • 47

3 Answers3

17

I just added

child.invalidate() 

before

final int childCenter = getCenterOfView(child); in getChildStaticTransformation(View child, Transformation t) 

so it becomes

protected boolean getChildStaticTransformation(View child, Transformation t) {

    child.invalidate();
    final int childCenter = getCenterOfView(child);
    final int childWidth = child.getWidth();
    int rotationAngle = 0;
kleopatra
  • 51,061
  • 28
  • 99
  • 211
Shantur
  • 171
  • 2
  • This also solves the problem of non rotating image views. Thanks. – Gunhan Nov 26 '13 at 12:24
  • I wish I can +1 more than once. fast solution (y) 1st search, 1st search result and from 1st code edit. Worked. – hasan Dec 19 '13 at 10:38
  • Is there a better way then call "invalidate()". In my Coverflow there are already a bunch of Images and thus its hurting my performance. – geri-m Mar 14 '14 at 21:38
3

Are you using Neil Davies Coverflow Widget V2?

If yes, I found out the problem. If no, I am sorry, I can't help you.

The problem is in the function getCenterOfView. More accurate, it is a problem about view.getLeft(). <-- please tell me if anyone know why it is different after 4.0

The value return from view.getLeft() is different at every time. So this will affect another function getChildStaticTransformation, it can't find which imageview is the center.

My solution, a dirty fix, is give a range for it to detect its center.

if (childCenter <= mCoveflowCenter + 125
            && childCenter >= mCoveflowCenter - 125) {
        transformImageBitmap((ImageView) child, t, 0);
}

Please let me know if anyone has a better solution on this.

Rush
  • 31
  • 2
  • It is Neils coverflow widget. I did not compare codes so I'm not sure if it is V2 or V1 :) I'll take a look at it, but as far as I remember I've tried to fix it in similar way to "expand" center to take +- 5 PX on both left and right, so it became a bit less smooth, but kind a work better. Will check this too. Tnx. – Balkyto Nov 06 '12 at 15:33
  • I run into same problem and use range as workaround for first time as well, but there is bad centering - depending on range value, so child in the middle is closer to the one of other childs and could overlap them after some scrolling. Now Im using invalidating as Shantur suggest and it works nice (i have only few items in coverflow, so invalidating does not hurt the performance) – Hruskozrout Dec 28 '12 at 22:59
2

I resolved following this code

private int offsetChildrenLeftAndRight() {
    int offset = 0;
    for (int i = getChildCount() - 1; i >= 0; i--) {

        getChildAt(i).offsetLeftAndRight(offset);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
            getChildAt(i).invalidate();
    }
    return offset;
}


final int childCenter = getCenterOfView(child) + offsetChildrenLeftAndRight();
user1273616
  • 31
  • 1
  • 3