ListView中重叠的项目?

时间:2015-04-11 13:17:31

标签: android listview android-listview android-custom-view

我正在尝试创建一个伪3D ListView,其中每个项目都与卡堆栈之类的其他东西重叠(见下文)。

card stack listview

我已经覆盖了ListView的drawChild方法,其中我正在做一些翻译工作&已达到上述目标。现在的问题是ListView只显示没有偏移的可见项目。

如何告诉ListView调整通过偏移项目创建的房间?

我的实施是:

@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;
}

我已经经历过:

但在那里找不到解决方案。

0 个答案:

没有答案