Make Coverflow Appear like a Horizontal Gallery Android
<p>I am trying to make the CoverFlow below appear like a Horizontal Gallery. The original file looks like this </p>

<p><img src="http://i.stack.imgur.com/iZpLe.png" alt="enter image description here"></p>

<p>There are three classes </p>

<ol>
<li><p>the CoverFlow.class which extends a gallery</p>

<pre><code>public class CoverFlow extends Gallery {

private Camera mCamera = new Camera();
private int mMaxRotationAngle = 50;
private int mMaxZoom = -380;
private int mCoveflowCenter;
private boolean mAlphaMode = true;
private boolean mCircleMode = false;
public CoverFlow(Context context) {
    super(context);
    this.setStaticTransformationsEnabled(true);
}
public CoverFlow(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.setStaticTransformationsEnabled(true);
}
public CoverFlow(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    this.setStaticTransformationsEnabled(true);
}
public int getMaxRotationAngle() {
    return mMaxRotationAngle;
}
public void setMaxRotationAngle(int maxRotationAngle) {
    mMaxRotationAngle = maxRotationAngle;
}
public boolean getCircleMode() {
    return mCircleMode;
}
public void setCircleMode(boolean isCircle) {
    mCircleMode = isCircle;
}
public boolean getAlphaMode() {
    return mAlphaMode;
}
public void setAlphaMode(boolean isAlpha) {
    mAlphaMode = isAlpha;
}
public int getMaxZoom() {
    return mMaxZoom;
}
public void setMaxZoom(int maxZoom) {
    mMaxZoom = maxZoom;
}
private int getCenterOfCoverflow() {
    return (getWidth() - getPaddingLeft() - getPaddingRight()) / 2
            + getPaddingLeft();
}
private static int getCenterOfView(View view) {
    return view.getLeft() + view.getWidth() / 2;
}
protected boolean getChildStaticTransformation(View child, 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) &gt; mMaxRotationAngle) {
            rotationAngle = (rotationAngle &lt; 0) ? -mMaxRotationAngle
                    : mMaxRotationAngle;
        }
        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;
    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 &lt;= mMaxRotationAngle) {
        float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
        mCamera.translate(0.0f, 0.0f, zoomAmount);
        if (mCircleMode) {
            if (rotation &lt; 40)
                mCamera.translate(0.0f, 155, 0.0f);
            else
                mCamera.translate(0.0f, (255 - rotation * 2.5f), 0.0f);
        }
        if (mAlphaMode) {
            ((ImageView) (child)).setAlpha((int) (255 - rotation * 2.5));
        }
    }
    mCamera.rotateY(rotationAngle);
    mCamera.getMatrix(imageMatrix);

    imageMatrix.preTranslate(-(imageWidth ), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth ), (imageHeight / 2));

    mCamera.restore();
}
</code></pre>

<p>}</p></li>
</ol>

<p>The second class is my coverFlowActivity which is my class class</p>

<pre><code>public class CoverFlowActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.main);

        CoverFlow cf = new CoverFlow(this);
        ImageAdapter ia = new ImageAdapter(this);
        cf.setAdapter(ia);
        cf.setAnimationDuration(1000);
        setContentView(cf);

    }

    public class ImageAdapter extends BaseAdapter {

        private int[] mImgs = {
                R.drawable.img1,
                R.drawable.img2,
                R.drawable.img3,
                R.drawable.img4,
                R.drawable.img5,
                R.drawable.img6,
                R.drawable.img7,
                R.drawable.img8
        };
        Context mContext;

        public ImageAdapter(Context context) {
            this.mContext = context;
        }
        @Override
        public int getCount() {
            return mImgs.length;
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return mImgs[position];

        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ReflectionImage i = new ReflectionImage(mContext);

            i.setImageResource(mImgs[position]);
            i.setLayoutParams(new CoverFlow.LayoutParams(100, 100));
            i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
            drawable.setAntiAlias(true);

            return i;
        }

        public float getScale(boolean focused, int offset) {
            return Math.max(0, 1f/(float)Math.pow(2, Math.abs(offset)));
        }

    }
}
</code></pre>

<p>and the third activity is the reflected image below each image.</p>

<pre><code>public class ReflectionImage extends ImageView {
    //ÊòØÂê¶‰∏∫ReflectionÊ®°Âºè
    private boolean mReflectionMode = true;
    public ReflectionImage(Context context) {
        super(context);
    }
    public ReflectionImage(Context context, AttributeSet attrs) {
        super(context, attrs);
        //ÂèñÂæóÂéüÂßãÂõæÁâáÁöÑbitmapÂπ∂ÈáçÁîª
        Bitmap originalImage = ((BitmapDrawable)this.getDrawable()).getBitmap();
        DoReflection(originalImage);
    }
    public ReflectionImage(Context context, AttributeSet attrs,
            int defStyle) {
        super(context, attrs, defStyle);
        Bitmap originalImage = ((BitmapDrawable)this.getDrawable()).getBitmap();
        DoReflection(originalImage);
    }
    public void setReflectionMode(boolean isRef) {
        mReflectionMode = isRef;
    }
    public boolean getReflectionMode() {
        return mReflectionMode;
    }
    //ÂÅ∑Êáí‰∫Ü,Âè™ÈáçÂÜô‰∫ÜsetImageResource,ÂíåÊûÑÈÄ†ÂáΩÊï∞ÈáåÈù¢Âπ≤‰∫ÜÂêåÊ†∑ÁöÑ‰∫ãÊÉÖ
    @Override
    public void setImageResource(int resId) {
        Bitmap originalImage = BitmapFactory.decodeResource(
                getResources(), resId);
        DoReflection(originalImage);
        //super.setImageResource(resId);
    }
    private void DoReflection(Bitmap originalImage) {
        final int reflectionGap = 4;                            //ÂéüÂßãÂõæÁâáÂíåÂèçÂ∞ÑÂõæÁâá‰∏≠Èó¥ÁöÑÈó¥Ë∑ù
        int width = originalImage.getWidth();
        int height = originalImage.getHeight();

        //ÂèçËΩ¨
        Matrix matrix = new Matrix();
        matrix.preScale(1, -1);
      //reflectionImageÂ∞±ÊòØ‰∏ãÈù¢ÈÄèÊòéÁöÑÈÇ£ÈÉ®ÂàÜ,ÂèØ‰ª•ËÆæÁΩÆÂÆÉÁöÑÈ´òÂ∫¶‰∏∫ÂéüÂßãÁöÑ3/4,ËøôÊ†∑ÊïàÊûú‰ºöÊõ¥Â•Ω‰∫õ
        Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0,
                0, width, height, matrix, false);
        //ÂàõÂª∫‰∏Ä‰∏™Êñ∞ÁöÑbitmap,È´òÂ∫¶‰∏∫ÂéüÊù•ÁöÑ‰∏§ÂÄç
        Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height), Config.ARGB_8888);
        Canvas canvasRef = new Canvas(bitmapWithReflection);

        //ÂÖàÁîªÂéüÂßãÁöÑÂõæÁâá
        canvasRef.drawBitmap(originalImage, 0, 0, null);
        //ÁîªÈó¥Ë∑ù
        Paint deafaultPaint = new Paint();
        canvasRef.drawRect(0, height, width, height + reflectionGap, deafaultPaint);

        //ÁîªË¢´ÂèçËΩ¨‰ª•ÂêéÁöÑÂõæÁâá
        canvasRef.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
        // ÂàõÂª∫‰∏Ä‰∏™Ê∏êÂèòÁöÑËíôÁâàÊîæÂú®‰∏ãÈù¢Ë¢´ÂèçËΩ¨ÁöÑÂõæÁâá‰∏äÈù¢
        Paint paint = new Paint();
        LinearGradient shader = new LinearGradient(0,
                originalImage.getHeight(), 0, bitmapWithReflection.getHeight()
                        + reflectionGap, 0x80ffffff, 0x00ffffff, TileMode.CLAMP);
        // Set the paint to use this shader (linear gradient)
        paint.setShader(shader);
        // Set the Transfer mode to be porter duff and destination in
        paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
        // Draw a rectangle using the paint with our linear gradient
        canvasRef.drawRect(0, height, width, bitmapWithReflection.getHeight()
                + reflectionGap, paint);
      //Ë∞ÉÁî®ImageView‰∏≠ÁöÑsetImageBitmap
        this.setImageBitmap(bitmapWithReflection);
    }
}
</code></pre>

<p>I want to make it appears like a gallery that is all images must have four dp margin and appear like the center image without any effects. Can someone please help me to achieve this.</p>
