2011.10.14(二)——— android 仿照微信的图片展示功能 之 放大超过屏幕

2011.10.14(2)——— android 仿照微信的图片展示功能 之 放大超过屏幕
2011.10.14(2)——— android 仿照微信的图片展示功能 之 放大超过屏幕

1、
<ImageView
		    	android:id="@+id/myImageView"
		    	android:layout_width="fill_parent"
		    	android:layout_height="fill_parent"
		    	android:scaleType="center"
				/>


我想是不是因为宽高设置的为fill_parent 所以造成了图片只能显示到屏幕大小呢

修改

android:layout_width="wrap_content"
android:layout_height="wrap_content"


运行之后  还是不行 依然只能在屏幕内显示


2、突然想起来 前两天做了一个只显示图片中间位置的例子
http://lipeng88213.iteye.com/admin/blogs/1180817


这个还是设计到 android:scaleType
因为系统默认是用fitCenter显示的
也就是按比例拉伸图片,拉伸后图片的高度为View的高度,且显示在View的中间 
按比例所以 原图是宽大于高 修改的图也将会是宽大于高的

所以我们可以改为center
<ImageView
		    	android:id="@+id/myImageView"
		    	android:layout_width="fill_parent"
		    	android:layout_height="fill_parent"
		    	android:scaleType="center"
				/>


哈哈 果然可以 效果如下:

2011.10.14(二)——— android 仿照微信的图片展示功能 之 放大超过屏幕


还有一个小功能 就是单击图片的话 隐藏下方的工具条

修改
<ImageView
		    	android:id="@+id/myImageView"
		    	android:layout_width="wrap_content"
		    	android:layout_height="wrap_content"
		    	android:scaleType="center"
				/>


改成wrap_content

增加touch监听

@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		Log.i(TAG, "onTouch...");
		if(isVisible){
			zoomControll.setVisibility(View.INVISIBLE);
			isVisible = false;
		}else{
			zoomControll.setVisibility(View.VISIBLE);
			isVisible = true;
		}
		return  super.onTouchEvent(event);    
	}


注册即可
mImageView.setOnTouchListener(this);



1 楼 mengsina 2012-02-17  
很受益。2011.10.14(二)——— android 仿照微信的图片展示功能 之 放大超过屏幕
2 楼 守夜之星 2012-04-13  
能给出详细代码吗? 578967344@qq.com