chrisbanes / PhotoView和UniversalImageLoader,缩放不起作用

时间:2014-10-27 09:35:05

标签: android android-fragments universal-image-loader

使用PhotoViewAttaccher和UniversalImageLoader我遇到了问题。 我在滑动片段中有4个片段,在UniversalImageloader检索图片后,我会缩放它。

这是活动:

public class FullPics extends FragmentActivity {
private static ViewPager pager;
private String directory;
private String link;
private static String pic_index;
private ImageLoader imageLoader;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_pics);

    link = this.getIntent().getExtras()
            .getString(this.getString(R.string.intent_link));

    pic_index = this.getIntent().getExtras()
            .getString(this.getString(R.string.extra_which), null);

    File cacheDir = StorageUtils.getCacheDirectory(this);
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            this).memoryCacheExtraOptions(480, 800)
            .taskExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
            .taskExecutorForCachedImages(AsyncTask.THREAD_POOL_EXECUTOR)
            .diskCache(new UnlimitedDiscCache(cacheDir))

            .diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
            .build();

    imageLoader = ImageLoader.getInstance();
    imageLoader.init(config);

    fragmentManager = getSupportFragmentManager();
    pager = (ViewPager) findViewById(R.id.pager);

    buildView(link);

}

public static void buildView(String link) {
    final FragmentAdapter fragmentAdapter = new FragmentAdapter(
            fragmentManager, link);

    pager.setAdapter(fragmentAdapter);
    pager.setPageMargin(0);
    pager.setOffscreenPageLimit(1);
    if (pic_index == null) {
        pager.setCurrentItem(0);
    } else {
        pager.postDelayed(new Runnable() {

            @Override
            public void run() {
                pager.setAdapter(fragmentAdapter);
                pager.setPageMargin(0);
                pager.setOffscreenPageLimit(1);
                pager.setCurrentItem(Integer.valueOf(pic_index));
            }
        }, 100);
    }
}

FragmentPagerAdapter是标准的,这是显示图像的单个片段:

public class SwipeFragment extends Fragment {
private String link;
private DisplayImageOptions doption;
private PhotoViewAttacher mAttacher;

public SwipeFragment(String link, String img_name) {
    this.link = link + "/" + img_name;

    doption = new DisplayImageOptions.Builder()
            .cacheInMemory(true)
            .displayer(new RoundedBitmapDisplayer(20)).build();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_swipe, container, false);

    ImageLoader imageLoader = ImageLoader.getInstance();

    final ImageView picture = (ImageView) view.findViewById(R.id.picture);

    mAttacher = new PhotoViewAttacher(picture);

    imageLoader.displayImage(link, picture, doption,
            new ImageLoadingListener() {

                @Override
                public void onLoadingStarted(String imageUri, View view) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onLoadingFailed(String imageUri, View view,
                        FailReason failReason) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onLoadingComplete(String imageUri, View view,
                        Bitmap loadedImage) {
                    Log.i("ATTACCHER", "end");

                    mAttacher.update();

                }

                @Override
                public void onLoadingCancelled(String imageUri, View view) {
                    // TODO Auto-generated method stub

                }

            });

    return view;
}

Everithing工作,但不是缩放。怎么了? 当我没有使用UniversalImageLoader库时,缩放效果很好。

1 个答案:

答案 0 :(得分:0)

我一直在做与此非常相似的事情。将图像加载到图像视图后,您是否尝试过将PhotoViewAttacher连接到imageview?

    View root = inflater.inflate(R.layout.imageview, container, false);
    ivImage = (testImageView) root.findViewById(R.id.ivImageView);
    setImageInImageView(ivImage);
    mAttacher = new PhotoViewAttacher(ivImage);

我有mAttacher.update(),只要imageview中的图像发生变化,它就适合我!