gpt4 book ai didi

Android PagerAdapter::获取当前项目到位图中

转载 作者:行者123 更新时间:2023-11-30 03:51:33 26 4
gpt4 key购买 nike

我正在为我的应用程序使用 UniversalImageLoader。我的 ImageAdapter 扩展了 PagerAdapter。我需要 currentImage 作为位图。通过回调方法 public void onLoadingComplete(Bitmap loadedImage) 我得到了位图。但这不是当前显示的位图图像。它是下一张图像或上一张图像(取决于交换)。这是完整的代码:

    private class ImagePagerAdapter extends PagerAdapter {
private String[] images;
private LayoutInflater inflater;

ImagePagerAdapter(String[] images) {
this.images = images;
inflater = getLayoutInflater();
}

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

@Override
public void finishUpdate(View container) {
}

@Override
public int getCount() {
return images.length;
}

@Override
public Object instantiateItem(View view, int position) {
if (view != null) {
final View imageLayout = inflater.inflate(
R.layout.item_pager_image, null);
final ImageView imageView = (ImageView) imageLayout
.findViewById(R.id.image_item_pager);

imageLoader.displayImage(images[position], imageView, options,
new ImageLoadingListener() {

@Override
public void onLoadingStarted() {
}

@Override
public void onLoadingFailed(FailReason failReason) {
//On Loading Failed Logic
}

@Override
public void onLoadingComplete(Bitmap loadedImage) {
bitmap = loadedImage;
imgViewSetAsWp.setImageBitmap(bitmap);
}

@Override
public void onLoadingCancelled() {
// Do nothing
}
});


((ViewPager) view).addView(imageLayout, 0);

return imageLayout;
} else
return view;
}

@Override
//Other override methood of ImagePager

}

有什么方法可以得到正确的位图。

最佳答案

如何获取当前 View - https://stackoverflow.com/a/8638772/913762

然后:

View currentView = ...
ImageView currentImageView = (ImageView) currentView.findViewById(...);
BitmapDrawable bd = (BitmapDrawable) currentImageView.getDrawable();
Bitmap bmp = bd.getBitmap();

关于Android PagerAdapter::获取当前项目到位图中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14079638/

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