bm-x / PhotoView

图片浏览缩放控件
2.63k stars 539 forks source link

viewpager+glide左右切换滑动会卡,不流畅 #108

Closed DuShuYuan closed 5 years ago

DuShuYuan commented 5 years ago

glide是4.0版本 如果加载本地资源滑动起来就很流畅 使用imageview+glide也很流程 代码: `vp.setAdapter(new PagerAdapter() { @Override public int getCount() { return urls.length; }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            PhotoView view = new PhotoView(mContext);
            view.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));
            view.enable();
            view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            ImageLoader.load(mContext, urls[position], view);
            container.addView(view);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });`

` public class ImageLoader {

public static void loadPhoto(Context context, String url, ImageView iv) {
    GlideApp.with(context).load(url).circlePhoto().into(iv);
}

public static void load(Context context, String url, ImageView iv) {
    Glide.with(context).load(url).into(iv);
}

public static void load(Context context, Uri uri, ImageView iv) {
    Glide.with(context).load(uri).into(iv);
}

} `

DuShuYuan commented 5 years ago

已解决: 使用glide回调加载图片

` Glide.with(mContext).load(urls[position]).into(new SimpleTarget() {

                @Override
                public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                    view.setImageDrawable(resource);
                }
            });

`