gpt4 book ai didi

android gallery 像查看寻呼机一样滚动

转载 作者:太空狗 更新时间:2023-10-29 16:22:13 26 4
gpt4 key购买 nike

我同时使用了 Gallery 和 ViewPager 小部件,我正在从网络服务中获取图像,但我无法将它们放在 ViewPager 中,但在 Gallery 中很容易。我将本教程用于 ViewPager http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/

我希望 android Gallery 小部件像 ViewPager 滚动一样滚动,

这可能吗,我该怎么做。

最佳答案

这是您的 PagerAdapter 的 instantiateItem() 方法的基本示例,它将动态地用 ImageView 填充它。

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

}

关于android gallery 像查看寻呼机一样滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11580566/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com