android画廊滚动像视图寻呼机

Rah*_*diq 2 android android-gallery android-viewpager

我使用了Gallery和ViewPager小部件,我从Web服务中获取图像,但我无法将它们放在ViewPager中,但在Gallery中很容易.我在ViewPager中使用了这个教程 http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizo​​ntal-view-paging/

我想要像ViewPager滚动一样的android Gallery小部件滚动,

这有可能,我该怎么办呢.

Foa*_*Guy 6

下面是PagerAdapter的instantiateItem()方法的一个简单示例,它将动态地填充图像视图.

@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;

}
Run Code Online (Sandbox Code Playgroud)