android gallery scroll like view pager

android, android-gallery, android-viewpager

Solution

Here is a bare bones example of the instantiateItem() method for your PagerAdapter that would fill it with image views dynamically.

@Override
public Object instantiateItem( final View pager, final int position )
{
    //Note: if you do not have a local reference to the context make one and
    //set it to the context that gets passed in to the constructor.
    //Another option might be to use pager.getContext() which is how its
    //done in the tutorial that you linked.
    ImageView mImg = new ImageView(context);

    /*Code to dynamically set your image goes here.
    Exactly what it will be is going to depend on 
    how your images are stored. 
    In this example it would be if the images
    are on the SD card and have filenames
    with incrementing numbers like: (img0.png, img1.png, img2.png etc...)*/

    Bitmap mBitmap = BitmapFactory.decodeFile(
         Environment.getExternalStorageDirectory() + "/img" + position + ".png");
    mImg.setImageBitmap(mBitmap);




    ((ViewPager) collection).addView(mImg, 0);
    return mImg;

}

Problem

I have used both Gallery and ViewPager widgets, I am fetching images from web service, but I couldn't place them in the ViewPager, but in Gallery it is easy. I used this tutorial for ViewPager http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/ I want android Gallery widget scroll like the ViewPager scroll, is this possible, how can I do this.

Original source