Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modern carousel library for android [closed]

Is there any library available for Carousel animation of images?

I found http://www.androidviews.net/2012/10/android-coverflow/ ; https://code.google.com/p/android-coverflow/ but this library/snippet use extends gallay (Gallery class was deprecated in API level 16. (4.1.2)), so is there any (modern) library? Maybe in combination with picasso?

like image 869
ternes3 Avatar asked Mar 30 '14 17:03

ternes3


3 Answers

I haven't found any such library available when searching for it, but when making my own app and using a ViewPager to display fragments, I've implemented my own class which implements ViewPager.PageTransformer.

Though you've asked for a library, I ran into a similar situation but ended up finding it easy enough to create my own class for it, so you may too. My guidance came from Using ViewPager for Screen Slides in the Google Developer documentation. Here is my code:

public class CarouselPageTransformer implements ViewPager.PageTransformer {
    @Override
    public void transformPage(View page, float position) {
        float scaleFactor = 0.5f;
        float rotationFactor = 20;

        if (position < 0) {
            page.setRotationY(rotationFactor * -position);
            float scale = 1 + scaleFactor * position;
            page.setScaleX(scale);
            page.setScaleY(scale);

        } else {
            page.setRotationY(rotationFactor * -position);
            float scale = 1 - scaleFactor * position;
            page.setScaleX(scale);
            page.setScaleY(scale);
        }
    }
}

The activity hosting the transform then calls:

viewPager.setPageTransformer(true, new CarouselPageTransformer());

This code positions the ViewPager's fragments to the sides of the visible screen, but you could just as easily position them to be visible, such as in the link you provided in your question.

Be aware of the minimum SDK required; from the documentation for ViewPager.PageTransform:

As property animation is only supported as of Android 3.0 and forward, setting a PageTransformer on a ViewPager on earlier platform versions will be ignored.

like image 64
phantomraa Avatar answered Nov 16 '22 10:11

phantomraa


Here is the free link of CarouselView Github Link and Android Arsenal

Gradle:

compile 'com.synnapps:carouselview:0.0.7'

Maven:

<dependency>
 <groupId>com.synnapps</groupId> 
 <artifactId>carouselview</artifactId>
 <version>0.0.7</version>
 <type>pom</type>
</dependency>

Usage:
Include following code in your layout:

<com.synnapps.carouselview.CarouselView
    android:id="@+id/carouselView"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    app:fillColor="#FFFFFFFF"
    app:pageColor="#00000000"
    app:radius="6dp"
    app:slideInterval="3000"
    app:strokeColor="#FF777777"
    app:strokeWidth="1dp"/>

Include following code in your activity:

public class SampleCarouselViewActivity extends AppCompatActivity {

CarouselView carouselView;

int[] sampleImages = {R.drawable.image_1, R.drawable.image_2, R.drawable.image_3, R.drawable.image_4, R.drawable.image_5};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample_carousel_view);

    carouselView = (CarouselView) findViewById(R.id.carouselView);
    carouselView.setPageCount(sampleImages.length);

    carouselView.setImageListener(imageListener);
}

ImageListener imageListener = new ImageListener() {
    @Override
    public void setImageForPosition(int position, ImageView imageView) {
        imageView.setImageResource(sampleImages[position]);
    }
};

}

If you want to add custom view, implement ViewListener.

public class SampleCarouselViewActivity extends AppCompatActivity {

CarouselView customCarouselView;
int NUMBER_OF_PAGES = 5;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample_carousel_view);

    customCarouselView = (CarouselView) findViewById(R.id.customCarouselView);
    customCarouselView.setPageCount(NUMBER_OF_PAGES);
    // set ViewListener for custom view 
    customCarouselView.setViewListener(viewListener);
}

ViewListener viewListener = new ViewListener() {

    @Override
    public View setViewForPosition(int position) {
        View customView = getLayoutInflater().inflate(R.layout.view_custom, null);
        //set view attributes here

        return customView;
    }
};

For more information go to github link

like image 27
Muhammad Nasir Shamshad Avatar answered Nov 16 '22 11:11

Muhammad Nasir Shamshad


Very Old Solution. Ignore

I have tried searching a lot for an alternative to Carousel. I finally found the perfect alternative.

InfiniteCycleViewPager

This does just what the Carousel library does.

I modified it to load images from my SD card rather than Drawables.

Works Perfectly fine.

like image 6
Devenom Avatar answered Nov 16 '22 10:11

Devenom