【问题标题】:Add Zoom in/out to ListView of Images?添加放大/缩小到图像列表视图?
【发布时间】:2016-04-22 13:24:31
【问题描述】:

我有一个包含 ListView 的片段,并且每次启动片段时都会替换多个图像 (7-10)。

我尝试使用不同的库进行缩放,但 ListView 不会显示,因为我必须将 ImageView 替换为库定义的 ImageView

如何为这些图像添加放大/缩小功能?

编辑:正如我的问题所述,我想在每次加载时包含不同数量的图像的ListView 添加放大/缩小。

编辑 2:这是我的 Custom Adapter 的 getview 方法。如何在其中附加PhotoViewAttacher?

public View getView(int position, View convertView, ViewGroup parent) {
    View iv = convertView;
    ViewHolder holder = null;

    if (iv == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        iv = inflater.inflate(layoutResourceId, parent, false);
        holder = new ViewHolder();

        holder.image = (ImageView) iv.findViewById(R.id.imagview);
        iv.setTag(holder);
    } else {
        holder = (ViewHolder) iv.getTag();
    }

    Picasso.with(context)
            .load((Integer) data.get(position))
            .resize(999, 720)
            .onlyScaleDown()
            .centerInside()
            .into(holder.image);

    return iv;
}

static class ViewHolder {
    ImageView image;
    PhotoViewAttacher mAttacher;
}

}

【问题讨论】:

  • @Rami 我已经写过我的图像在ListView 中,如果我使用库(如该问题的答案中所述)进行缩放,它将不会加载ListView,库我遇到的是单身ImageViews。
  • 你能用你实现的缩放方法添加代码,以便我们尝试找出问题所在吗?
  • @Anders 当然它们适用于单个 ImageView,您可以在适配器的 getView() 方法中使用它们并将动画应用到您的列表项 ImageView。
  • 我通过我的自定义适配器尝试了一个ImageViewTouch,但我的列表在添加后不会显示,因为我必须使用该库自己的图像视图。所以我认为它不会那样工作,让我用那个问题中描述的 lib 再试一次,然后我会更新我的问题。

标签: android listview android-listview zooming


【解决方案1】:

这就是我的工作方式

导入PhotoView后

在布局文件中(如果你使用布局):

<uk.co.senab.photoview.PhotoView
    android:id="@+id/your_photo_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    ... />

在适配器中

PhotoView photoView = (PhotoView) findViewById(R.id.your_photo_view);

Picasso.with(context)
    .load(file)
    ...
    .into(photoView); 

感谢大家的宝贵时间。

【讨论】:

  • +1 表示好的 qtn..-1 表示不好的答案。请从该链接发布答案..该链接将来可能不可用。
  • 撤消我的反对票。uk.co.senab.photoview.PhotoView 图书馆链接在哪里?
  • 只允许我一个赞成票:).. 已经赞成..谢谢你的好回答。
【解决方案2】:

而不是在BaseAdapter的getView列表项中添加简单的ImageView TouchImageView

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    相关资源
    最近更新 更多