Search code examples
androidcarouselandroid-custom-view

Carousel view implementation like listview scrolling


Anyone has implemented like the below carousel? Note: The list of items should not be repeated, means should not come to first after reaching the last item. Please help me on this.

carousel listview

[edited]

enter image description here

I don't want to use ListView for this. anyone help me on this. Thanks...


Solution

  • this should get you started. Override your ListView like so:

    private final Transformation mTransformation;
    
    public ListView3d(Context context, AttributeSet attrs) {
        super(context, attrs);
        if (!isInEditMode()) {
            setStaticTransformationsEnabled(true);
            mTransformation = new Transformation();
            mTransformation.setTransformationType(Transformation.TYPE_MATRIX);
        } else {
            mTransformation = null;
        }       
    }
    
    @Override
    protected boolean getChildStaticTransformation(View child, Transformation t) {
        mTransformation.getMatrix().reset();
        final int childTop = Math.max(0,child.getTop());
        final int parentHeight = getHeight();
        final float scale = (float)(parentHeight-(childTop/2))/getHeight();
        Log.i("scale",scale+"");
        final float px = child.getLeft() + (child.getWidth()) / 2;
        final float py = child.getTop() + (child.getHeight()) / 2;
        mTransformation.getMatrix().postScale(scale, scale, px, py);
        t.compose(mTransformation);
        return true;
    }
    

    in getChildStaticTransformation you can achieve various effects (even 3d) by manipulating the matrix accordingly. A very good tutorial (which uses another technique can be found here.