I've implemented Android Coverflow sample. On click of the image, I can retrieve its position and display the image in the ImageView. My other requirement is to focus the image in the coverFlow when I pass its Id. I should bring the focussed image to the center. This is the code for calculating the angle between the images during transformation. How can I change it to achieve the required output?
protected boolean getChildStaticTransformation(final View child, final Transformation t) {
final int childCenter = getCenterOfView(child);
final int childWidth = child.getWidth();
int rotationAngle = 0;
t.clear();
t.setTransformationType(Transformation.TYPE_MATRIX);
if (childCenter == mCoveflowCenter) {
transformImageBitmap((ImageView) child, t, 0);
} else {
rotationAngle = (int) ((float) (mCoveflowCenter - childCenter) / childWidth * mMaxRotationAngle);
if (Math.abs(rotationAngle) > mMaxRotationAngle) {
rotationAngle = rotationAngle < 0 ? -mMaxRotationAngle : mMaxRotationAngle;
}
transformImageBitmap((ImageView) child, t, rotationAngle);
}
return true;
}
private void transformImageBitmap(final ImageView child, final Transformation t, final int rotationAngle) {
mCamera.save();
final Matrix imageMatrix = t.getMatrix();
final int height = child.getLayoutParams().height;
final int width = child.getLayoutParams().width;
final int rotation = Math.abs(rotationAngle);
mCamera.translate(0.0f, 0.0f, 100.0f);
// As the angle of the view gets less, zoom in
if (rotation < mMaxRotationAngle) {
final float zoomAmount = (float) (mMaxZoom + rotation * 1.5);
mCamera.translate(0.0f, 0.0f, zoomAmount);
}
mCamera.rotateY(rotationAngle);
mCamera.getMatrix(imageMatrix);
imageMatrix.preTranslate(-(width / 2.0f), -(height / 2.0f));
imageMatrix.postTranslate((width / 2.0f), (height / 2.0f));
mCamera.restore();
}
You can achieve this using setOnItemSelectedListener of coverFlow. see below is the code in which you will get position of center image.
Now,you can change focus the image in the coverFlow in getview method of adapter.
Hop this will help you.