Search code examples
androidandroid-viewpageruniversal-image-loader

Image isn't displayed in ImageViewZoom


I'd like to use ImageViewZoom with Universal Image Loader in ImagePagerActivity.

So, what I did:

  1. I added imageviewtouch.jar to project classpath.
  2. In ImagePagerActivity I changed one line in instantiateItem() function. I commented line where is ImageView and replaced it to ImageViewTouch (4. and 5. line)

    @Override
    public Object instantiateItem(View view, int position) {
        final View imageLayout = inflater.inflate(R.layout.item_pager_image, null);
        //final ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);
        final ImageViewTouch imageView = (ImageViewTouch) imageLayout.findViewById(R.id.image);
    
        final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loading);
        final TextView textView = (TextView)imageLayout.findViewById(R.id.text);
    
        imageLoader.displayImage(images[position], imageView, options, new ImageLoadingListener() {
    
    
            public void onLoadingStarted() {
                spinner.setVisibility(View.VISIBLE);
            }
    
    
            public void onLoadingFailed(FailReason failReason) {
                String message = null;
                switch (failReason) {
                    case IO_ERROR:
                        message = "Input/Output error";
                        break;
                    case OUT_OF_MEMORY:
                        message = "Out Of Memory error";
                        break;
                    case UNKNOWN:
                        message = "Unknown error";
                        break;
                }
                Toast.makeText(ImagePagerActivity.this, message, Toast.LENGTH_SHORT).show();
    
                spinner.setVisibility(View.GONE);
                imageView.setImageResource(android.R.drawable.ic_delete);
            }
    
    
            public void onLoadingComplete(Bitmap loadedImage) {
                spinner.setVisibility(View.GONE);
                Animation anim = AnimationUtils.loadAnimation(ImagePagerActivity.this, R.anim.fade_in);
                imageView.setAnimation(anim);
                anim.start();
            }
    
    
            public void onLoadingCancelled() {
                // Do nothing
            }
        });
    
        ((ViewPager) view).addView(imageLayout, 0);
        return imageLayout;
    }
    
  3. In /res/layout/item_pager_image.xml I replace ImageView to it.sephiroth.android.library.imagezoom.ImageViewTouch

     <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="1dip" >
    
      <it.sephiroth.android.library.imagezoom.ImageViewTouch
         android:layout_weight="1"
         android:id="@+id/image"
         android:layout_width="match_parent"
         android:layout_height="0dp"
         android:scaleType="fitCenter" />
    
      <ProgressBar
        android:id="@+id/loading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="gone" />
    
    </FrameLayout>
    

I run this Android application, but when I choose Image Pager in menu screen, there is no image displayed, only black screen. In logcat I see that image was downloaded and displayed... If I change ImageViewTouch to original ImageView, everything is OK, but of course there is no zoom feature. If someone knows what I do wrong, I'd be very grateful. (sorry for my English)


Solution

  • Change ImageViewTouch parameter from android:layout_height="0dp" to other value.