Android之PhtoView设置图片放大缩小后,当调用mAttacher = new PhotoViewAttacher(imageView) 。图片显示在界面上左上角。在网上找了很久也没找到解决办法,看来只能靠本身了。 java
找到源代码,发现里面有个PhotoView类,再一看这个是继承自ImageView。那么为何要继承自ImageView呢。难道这是个自定义控件。好吧,我带布局文件中直接使用了自定义的这个控件。 android
具体布局文件以下: 布局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@drawable/zhidao_details_tv_bg" > <uk.co.senab.photoview.PhotoView <!--注意这里的用的不是ImageView--> android:id="@+id/img_schedule" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_centerInParent="true"/> </RelativeLayout>
而后在代码里, this
private PhotoView imageView; ...... imageView = (PhotoView) this.findViewById(R.id.img_schedule); ...... ImageLoader.getInstance().displayImage(imageUrl,imageView); mAttacher = new PhotoViewAttacher(imageView);//这句写上以后就能够多点触摸方法缩小啦。
发表一下感慨,遇到问题时不要轻言放弃。静下心来,仔细分析分析。说不定哪一个瞬间就找到解决问题的方法了。 spa
这个问题找了很久貌似都没有找到答案。这里分享给你们,但愿对你们有帮助。若是以为有用,不妨赞一下哦~ O(∩_∩)O哈哈~ code
附PhotoView的library下载地址: http://pan.baidu.com/s/1rJIaL xml
若是有任何疑问,欢迎Email to me :junkedeng@163.com 继承