I am trying to make a pseudo 3d ListView in which each item overlaps other something like a card stack (see below).
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.