【问题标题】:android gallery scroll like view pagerandroid画廊滚动像查看寻呼机
【发布时间】:2012-07-20 13:41:38
【问题描述】:

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

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

这可能吗,我该怎么做。

【问题讨论】:

  • 请注意,Gallery widget 现在已弃用。您可能应该使用 ViewPager。如果您可以编辑您的问题并发布您在尝试 ViewPager 时遇到的问题,我们可以尝试帮助您以这种方式解决问题。
  • @Tim 我编辑了我的问题,检查,如何动态创建视图并添加它们,我还想要一个点击监听器
  • 如果你只使用 ViewPager 它可以解决问题,你只需要在寻呼机的视图(实际上是布局)中指定你想要显示的内容,然后处理点击事件(在特定视图上)。

标签: android android-viewpager android-gallery


【解决方案1】:

这是您的 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;

}

【讨论】:

  • 它完美运行只有一个问题,我不知道为什么它在右侧没有显示褪色效果,它只在左侧显示褪色效果,我阅读了一些博客,很少有问题它仅在左侧和顶部显示褪色,需要覆盖右侧的方法(getRightEdgeFading),有什么建议吗???
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多