Android Gallery 中 CoverFlow 中的错误图像重叠

标签 android gallery coverflow

我正在修补 CoverFlow from here以满足我的喜好并且无法解决一个问题。这是屏幕截图:

screenshot

中心图像右侧的图片重叠得很严重。这是我的代码:

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();
}

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

最佳答案

您已通过重写 Gallery 类的 getChildDrawingOrder 函数指定了正确的顺序。上述行为可以通过以下代码来实现:

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

关于Android Gallery 中 CoverFlow 中的错误图像重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11735422/

相关文章:

android - 如何在 Android Studio 中设置数据绑定(bind)的默认值?

java - 执行cursor.getCount() 时崩溃(Android)

jquery - 使用 jQuery 和 css3 的 Coverflow

iphone - 适用于 iPhone/iPod Touch 的 HTML5 中的 Coverflow

java - Android 上的简单 XML - 类 MyArrayList<E> 扩展了 ArrayList<E>?

Android 9 ResolvableApiException onActivityResult 有 resultCode 0 RESULT_CANCELED

android - 从 Android 手机获取图像和视频到自定义图库

安卓图库 : how to detect that an item has shifted in Gallery (and shift direction)

java - 有没有其他方法可以在不使用 webview 和 Html.fromHtml() 方法的情况下在 Android TextView 中显示 Html 代码?

jquery - 通过鼠标悬停/移出 div 淡入/淡出 div 中的元素