【问题标题】:What's the best way on Android to create a photo gallery (fullscreen)在 Android 上创建照片库的最佳方式是什么(全屏)
【发布时间】:2012-07-13 08:49:14
【问题描述】:

我想知道为我的应用创建照片库的最佳方式是什么。我从 RSS 提要中获取图片,我想全屏显示它们。我应该使用什么?我尝试使用 ImageView,但图像的大小调整不当(它们不保持原始尺寸)

我用这个答案来实现我的画廊:Android Gallery fullscreen

谢谢

编辑:

这是 XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <android.support.v4.view.ViewPager
        android:id="@+id/galleryPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

    </android.support.v4.view.ViewPager>

</LinearLayout>

这是我在适配器中用来加载图像的代码:

@Override
public Object instantiateItem(View collection, int position) {
    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    ImageDownloader.getInstance().download(gallery.get(position), ImageFormat.CONTENT_316, imageView);

        ((ViewPager) collection).addView(imageView, 0);

        return imageView;
}

【问题讨论】:

  • 其他人留下了评论建议,该评论显然已被删除。

标签: android imageview photo-gallery


【解决方案1】:

我会使用一个ViewPager,里面有ImageViews。

您可以使用 xml 中的 android:scaleType 属性向 ImageView 指定您希望(或不)如何拉伸图像。如果您分享一些您在 ImageViews 中使用的代码,并且可能提供更多关于您希望它们如何显示的信息,我可以尝试帮助您正确设置它。

另外,我建议您查看Displaying Bitmaps Efficiently,了解处理图像时使用的最佳实践,以保持您的应用程序的性能一流。

【讨论】:

  • 感谢您的回答,我发布了我的代码。使用此代码,图像会失去比例*
【解决方案2】:

使用AdapterListView 显示图片幻灯片。

现在在适配器项的布局中使用 ImageViewfill_parent 来表示宽度和高度,如下代码所示:

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY" />

您可以建议用户在横向模式下使用手机以获得更好的性能。所以在 layout-land 文件夹中保留额外的布局

【讨论】:

    【解决方案3】:

    一种方法是

    • 从 rss 提要中获取图片 url
    • 在自定义图库中将它们显示为缩略图(可以通过水平线性布局设置,其中包含图像视图,在滚动视图内)
    • 使用延迟加载图像来显示这些缩略图
    • 重写 onClickListener 以获取点击事件
    • 并在此 onClick 中加载 web 视图中的当前图像 URL。
    • webview 具有很好的缩放、图片移动等功能。

    【讨论】:

      【解决方案4】:

      我上面使用的代码几乎是对的,我只是将 ImageView.ScaleType.FIT_XY 更改为 ImageView.ScaleType.CENTER_CROP

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical" >
      
          <android.support.v4.view.ViewPager
              android:id="@+id/galleryPager"
              android:layout_width="match_parent"
              android:layout_height="match_parent" >
      
          </android.support.v4.view.ViewPager>
      
      </LinearLayout>
      

      这是我在适配器中用来加载图像的代码:

      @Override
      public Object instantiateItem(View collection, int position) {
          ImageView imageView = new ImageView(context);
          imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
          imageView.setScaleType(**ImageView.ScaleType.CENTER_CROP**);
          ImageDownloader.getInstance().download(gallery.get(position), ImageFormat.CONTENT_316, imageView);
      
              ((ViewPager) collection).addView(imageView, 0);
      
              return imageView;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-09-09
        • 1970-01-01
        • 1970-01-01
        • 2017-07-31
        • 1970-01-01
        • 2022-01-05
        • 1970-01-01
        • 2012-09-01
        相关资源
        最近更新 更多