sayyam / carouselview

A simple library to add carousel view in android app.
Apache License 2.0
1.15k stars 260 forks source link

fit Width and scale height of CarouselView to show all image #60

Open domoemmanuel99 opened 7 years ago

domoemmanuel99 commented 7 years ago

how can i show all the image without cut any part of image?, i want to download the images from internet with glide, and place it inside the carousel, but when i do it, the image gets cropped on the bottom or on sides(thats beacuse Carouselview has a fixed height and widht variates with screen size), any way to only scale the carouselview height to fit image?(if i set height on wrapcontent the view disapears)how can i acomplish that?

omjokine commented 7 years ago

You cannot do this with setImageListener because it sets imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); by default.

You could use setViewListener instead, for example:

carouselView.setViewListener(new ViewListener() {
    @Override
    public View setViewForPosition(int position) {
        ImageView imageView = new ImageView(getActivity());
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        Picasso.with(getActivity())
                .load("http://url.to/image.jpg")
                .fit()
                .centerInside()
                .into(imageView);
        return imageView;
    }
});
omjokine commented 7 years ago

Actually my answer was a bit over-engineered. Should be enough just to set scaleType for imageView in ImageListener:

carouselView.setImageListener((position, imageView) -> {
    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    ...
mohdqasim commented 4 years ago

Actually my answer was a bit over-engineered. Should be enough just to set scaleType for imageView in ImageListener:

carouselView.setImageListener((position, imageView) -> {
    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    ...

imageView.setScaleType(ImageView.ScaleType.FIT_XY); this is also an option

Selmeny commented 3 years ago

I have tried both FIT_CENTER and FIT_XY and it's still not working. Any idea?