Youssef
Youssef

Reputation: 169

Android Gallery Component

I am looking for Android Gallery component like this : enter image description here

Tha Gallery class in deprecated in new version of SDK, so i don't know if there any other componeent like that.

Regards

Upvotes: 1

Views: 296

Answers (1)

Robin Bruneel
Robin Bruneel

Reputation: 1101

You should use a ViewPager with a Viewpager.PageTransformer, here you find examples: https://github.com/geftimov/android-viewpager-transformers

You must use negative pagemargin to see the one left and the one right. (https://developer.android.com/reference/android/support/v4/view/ViewPager.html#setPageMargin(int))

This is the code of the PageTransformer in Xamarin Android, you can quickly modify it to use it on native Android. Make a ViewPager_Transform_CenterBig object and use yourViewpager.setPageTransformer(false, new ViewPager_Transform_CenterBig(0.90f)); to set the transformer

public class ViewPager_Transform_CenterBig: Java.Lang.Object, ViewPager.IPageTransformer
{
    public float Scale {
        get;
        private set;
    }

    public ViewPager_Transform_CenterBig (float scale)
    {
        Scale = scale;
    }

    #region IPageTransformer implementation

    public void TransformPage (Android.Views.View page, float position)
    {
        int pageWidth = page.Width;
        int pageHeight = page.Height;
         if (position <= 1) { 
            // [-1,1]
            // Modify the default slide transition to shrink the page as well
            float scaleFactor = Math.Max (Scale, 1 - Math.Abs (position)* 0.3f);
            float vertMargin = pageHeight * (1 - scaleFactor) * 0.5f;
            float horzMargin = pageWidth * (1 - scaleFactor) * 0.5f;
            page.TranslationX = position < 0 
                ? (horzMargin - vertMargin * 0.5f) 
                : (-horzMargin + vertMargin * 0.5f);

            // Scale the page down (between MIN_SCALE and 1)
            page.ScaleX = (scaleFactor);
            page.ScaleY = (scaleFactor);
        } 
    }

    #endregion

}

Upvotes: 1

Related Questions