在CoverFlow中Android Gallery坏图像重叠

mgl*_*sty 2 android gallery coverflow

从这里修补CoverFlow 以符合我的偏好,无法解决一个问题.这是截图:

截图

中心图像右侧的图片以不良方式重叠.这是我的代码:

protected boolean getChildStaticTransformation(View child, Transformation t) {

  final int childCenter = getCenterOfView(child);
  int rotationAngle = 0;
  t.clear();
  t.setTransformationType(Transformation.TYPE_MATRIX);

    if (childCenter == mCoveflowCenter) {
        transformImageBitmap((ImageView) child, t, 0);
    } else {      
        rotationAngle = Math.abs(mCoveflowCenter - childCenter);
        transformImageBitmap((ImageView) child, t, rotationAngle);         
    }    

return true;
}

/**
* This is called during layout when the size of this view has changed. If
* you were just added to the view hierarchy, you're called with the old
* values of 0.
*
* @param w Current width of this view.
* @param h Current height of this view.
* @param oldw Old width of this view.
* @param oldh Old height of this view.
 */
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  mCoveflowCenter = getCenterOfCoverflow();
  super.onSizeChanged(w, h, oldw, oldh);
 }

 /**
  * Transform the Image Bitmap by the Angle passed 
  * 
  * @param imageView ImageView the ImageView whose bitmap we want to rotate
  * @param t transformation 
  * @param rotationAngle the Angle by which to rotate the Bitmap
  */
 private void transformImageBitmap(ImageView child, Transformation t, int rotationAngle) {            
  mCamera.save();
  final Matrix imageMatrix = t.getMatrix();
  final int imageHeight = child.getLayoutParams().height;
  final int imageWidth = child.getLayoutParams().width;

  mCamera.translate(0.0f, 0.0f, 100.0f);

  float zoomAmount = 0;
  //skalowanie za pomoc? translate nie rotational angle?
  zoomAmount = Math.abs((float) (rotationAngle));

  Log.v("zoom", Float.toString(zoomAmount));
  mCamera.translate(0.0f, 0.0f, zoomAmount - 300.0f);          

  mCamera.getMatrix(imageMatrix);               
  imageMatrix.preTranslate(-(imageWidth/2), -(imageHeight/2)); 
  imageMatrix.postTranslate((imageWidth/2), (imageHeight/2));
  mCamera.restore();
}
Run Code Online (Sandbox Code Playgroud)

它为每张照片转换相机,因此较小的照片更多地进入屏幕(在logcat值中是完美的).这是什么意思?我是否必须先绘制较小的图片,然后再绘制较大的图片等?如果是这样,我该怎么做?

小智 5

您已通过覆盖getChildDrawingOrderGallery类的功能指定了正确的顺序.以下行为可以通过以下代码实现:

int lastPosition;

@Override
protected int getChildDrawingOrder(int childCount, int i) {

    if (i == 0)
        lastPosition = 0;

    int centerPosition = getSelectedItemPosition()
            - getFirstVisiblePosition();

    if (i == childCount - 1) {
        return centerPosition;
    } else if (i >= centerPosition) {
        lastPosition++;
        return childCount - lastPosition;
    } else {
        return i;
    }
}
Run Code Online (Sandbox Code Playgroud)