1

I am trying to make a pseudo 3d ListView in which each item overlaps other something like a card stack (see below).

card stack listview

I have overridden ListView's drawChild method, in which I am doing some translation stuffs & have achieved above. Now problem is that ListView is only showing the items that were visible without the offsetting.

How can I tell ListView to adjust for the room created by offsetting the items ?

My implementation is:

@Override
protected boolean drawChild(final Canvas canvas, final View child, final long drawingTime) {
    Bitmap bitmap = getChildDrawingCache(child);   

    // center point of child
    final int childCenterY = child.getHeight() / 2;

    //center of list
    final int parentCenterY = getHeight() / 2;

    //center point of child relative to list
    final int absChildCenterY = child.getTop() + childCenterY;

    //distance of child center to the list center
    final int distanceY = parentCenterY - absChildCenterY;

    //radius of imaginary cirlce
    final int r = getHeight() / 2;

    if (mMatrix == null) {
        mMatrix = new Matrix();
    }

    prepareMatrix(mMatrix, distanceY, r, child.getHeight());

    canvas.drawBitmap(bitmap, mMatrix, mPaint);

    return false;
}

private void prepareMatrix(final Matrix outMatrix, float distanceY, float r, float heightChild){
    if (mCamera == null) {
        mCamera = new Camera();
    }

    mCamera.save();

    float visibility = ((distanceY/r) * (2*heightChild/3));

    mCamera.getMatrix(outMatrix);

    outMatrix.setTranslate(0, (heightChild - visibility));

    mCamera.restore();
}

private Bitmap getChildDrawingCache(final View child){
    Bitmap bitmap = child.getDrawingCache();
    if (bitmap == null) {
        child.setDrawingCacheEnabled(true);
        child.buildDrawingCache();
        bitmap = child.getDrawingCache();
    }
    return bitmap;
}

I have already gone through:

But could not find solution for there.

Community
  • 1
  • 1
Varun Oberoi
  • 682
  • 6
  • 20
  • Alternate idea: What about configuring an `ExpandableListView`? – Phantômaxx Apr 11 '15 at 13:21
  • I would like to animate cards while scrolling – Varun Oberoi Apr 11 '15 at 13:34
  • @Varun do you get any idea for that how to implement this type of list view – Sameer Donga Oct 27 '15 at 05:20
  • @SameerDonga Google introduced [RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html) for these kind of listviews. Go through [this tutorial](http://wiresareobsolete.com/2014/09/building-a-recyclerview-layoutmanager-part-1/) for its implementation. – Varun Oberoi Oct 27 '15 at 17:12

0 Answers0