2012-07-31 71 views
2

我在修補CoverFlow from here以符合我的偏好,並且無法解決一個問題。下面是截圖:Android圖庫在CoverFlow中重疊的圖像不良

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

它translatimg相機每張照片,所以較小的圖片更到屏幕(在logcat中值是完美的)。這是什麼意思?我是否必須首先繪製較小的圖片,然後再繪製較大的圖片等?如果是這樣,我該怎麼做?

回答

0
mCamera.translate(xTranslate, 0.0f, translateDepth); 

Coverflow類使用上述功能,以增加的深度(更多正=更多更小)在X方向或平移。你也可以使用一些縮放。同樣使用centerOffset值。達到目的。

+0

你好,阿吉特,請看看這個問題的http:/ /stackoverflow.com/questions/18864772/carousel-animation-in-android – Hasmukh 2013-10-11 06:25:16

+0

當我使用封面流程,並嘗試修改代碼按照您的重播這裏,但我沒有得到這個地方使用這一個。如果您對此有任何想法,請提供幫助。提前致謝。 – Hasmukh 2013-10-11 06:27:28

5

您已指定正確的順序,方法是重寫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; 
    } 
} 
+1

你真的幫了我...... +1 – 2012-11-23 06:22:08

+0

請加滿code..I需要,迫切 – 2013-10-21 06:17:00

+0

不要忘記調用'setChildrenDrawingOrderEnabled(真);' – 2014-01-22 12:43:22