图像未显示在图像视图缩放中



我想在ImagePagerActivity中使用ImageViewZoom和Universal Image Loader。

所以,我做了什么:

  1. 我将 imageviewtouch.jar 添加到项目类路径中。
  2. 在 ImagePagerActivity 中,我在 instantiateItem() 函数中更改了一行。我评论了ImageView所在的行,并将其替换为ImageViewTouch(4.和5.行)

    @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. 在/res/layout/item_pager_image.xml 中,我将 ImageView 替换为 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>
    

我运行这个Android应用程序,但是当我在菜单屏幕中选择图像寻呼机时,没有显示图像,只有黑屏。在日志猫中,我看到图像已下载并显示...如果我将ImageViewTouch更改为原始ImageView,一切都很好,但当然没有缩放功能。如果有人知道我做错了什么,我将不胜感激。(对不起我的英语)

ImageViewTouch 参数从 android:layout_height="0dp" 更改为其他值。

最新更新