Search code examples
android-kenburnsview

Make KenBurnsView fit and fill given area


My App uses KenBurnsView (wonderful piece of code, thanks!), and it works well with ScaleType.FIT_CENTE mode, but some users just prefer to see the whole, non cropped image instead (non moving in that case), which works pretty well with standard ImageView, but fails miserably with KenBurns:

    if (XenoAmp.getWpsCover()) {
        final KenBurnsView caly = (KenBurnsView) widok.findViewById(R.id.tlo);
        if (XenoAmp.getCoverFill()) {
            caly.setScaleType(ScaleType.FIT_CENTER);
        } else {
            caly.setScaleType(ScaleType.CENTER_INSIDE);
            caly.pause();
        }
    }

What happens with Ken is: he stays small and sticks to upper left corner of parent view. How can I fix that without replacing it with standard ImageView?


Solution

  • You can take two different approaches:

    1. Use a standard ImageViewtogether with KenBurnsView and switch visibilities according to what your users want to see.

    2. Write your own TransitionGenerator that doesn't do any transition at all. You can find some information about how to do it here: Define zoom/pan start position with KenBurnsView

    IMO, the former approach is much simpler and makes more sense.