¾È±Ô °øºÎ¹æ

Android > ¸ÖƼÅÍÄ¡ ÇÉÄ¡ÁÜ(Pinch Zoom) ±â´É ±¸ÇöÇϱâ (PhotoView ¶óÀ̺귯¸®)

µî·ÏÀÏ : 2017-07-05 19:06 Á¶È¸¼ö : 54,264

 

¾Èµå·ÎÀ̵å ÇÁ·Î±×·¡¹ÖÀ» ÇÏ´Ùº¸¸é ImageView À̹ÌÁö¸¦ µÎ ¼Õ°¡¶ô(¸ÖƼÅÍÄ¡)À¸·Î È®´ë, Ãà¼Ò°¡ °¡´ÉÇÏ°Ô ÇÉÄ¡ ÁÜ(Pinch Zoom) ±â´ÉÀ»

±¸ÇöÇØ¾ß ÇÒ ¶§°¡ ÀÖ½À´Ï´Ù.

ÀÌ·¯ÇÑ ±â´ÉÀ» Á¦°øÇÏ´Â ±âº» À§Á¬ÀÌ ÀÖÀ¸¸é ÁÁ°ÚÁö¸¸ ¾øÁÒ. ±×·¸´Ù°í ½±°Ô ±¸ÇöÇÒ ¼ö ÀÖ´Â ³»¿ëÀÌ ¾Æ´Õ´Ï´Ù.

OnTouchEvent À̺¥Æ®¸¦ Ãß°¡Çؼ­ ó¸®ÇØ¾ß ÇÏ°í, getPointerCount() ÇÔ¼ö·Î µÎ ¼Õ°¡¶ôÀÎÁöµµ üũÇØ¾ß Çϸç, ÁÜÇÑ °Å¸®¸¦ °è»êÇϱâ À§ÇØ

º¹ÀâÇÑ »ê¼öµµ ÇؾßÇÕ´Ï´Ù.

°Å±â¿¡´Ù È®´ë°¡ µÈ À̹ÌÁö¿¡ ½ºÅ©·Ñ ±â´Éµµ Ãß°¡Çؼ­ º¸°í ½ÍÀº ºÎºÐÀ» º¼ ¼ö ÀÖ°Ô Á¶Àý ÇÒ ¼öµµ ÀÖ¾î¾ß ÇÕ´Ï´Ù.

Á÷Á¢ ÄÚµùÇÏ°Ú´Ù°í ¸¸¸¸ÇÏ°Ô ´ýº³´Ù°¡´Â ¾öû³­ ¹ö±×¸¦ ¾ç»ê ÇÒ ¼öµµ ÀÖÁÒ.

°øºÎ»ï¾Æ Á÷Á¢ Â¥º¸´Â °Íµµ ÁÁÁö¸¸ °³¹ßÀÚÀÇ ÀÔÀå¿¡¼± Àß ¸¸µé¾î ³õÀº ¶óÀ̺귯¸®¸¦ »ç¿ëÇÏ´Â °ÍÀÌ Çö¸íÇÕ´Ï´Ù.

¿©±â¼­µµ ÁýÀû ÇÉÄ¡ ÁÜ ±â´ÉÀ» ±¸ÇöÇÏ´Â °ÍÀÌ ¾Æ´Ï¶ó, ÆíÇÏ°Ô »ç¿ë ÇÒ ¼ö ÀÖ´Â PhotoView ¶óÀ̺귯¸®¸¦ »ç¿ëÇϵµ·Ï ÇÏ°Ú½À´Ï´Ù

https://github.com/chrisbanes/PhotoView




https://github.com/chrisbanes/PhotoView/releases

ÀÌ ±ÛÀ» ¾²±â¿¡ ¾Õ¼­ ¸ÚÁø ÇÉÄ¡ ÁÜ ±â´É(PhotoView)À» ¿ÀǼҽº·Î ¸¸µé¾îÁØ Chris Banes´Ô²² °¨»çÀÇ ¸»¾¸À» µå¸³´Ï´Ù.

PhotoView´Â ¾ÆÆÄÄ¡ ¶óÀ̼±½º¸¦ µû¸£°í ÀÖÀ¸´Ï Âü°íÇϽñ⠹ٶø´Ï´Ù. À§ ¸µÅ© GitHub PhotoView ÆäÀÌÁö¿¡¼­ PhotoView ¶óÀ̺귯¸®¸¦ ´Ù¿î¹ÞÀ» ¼ö ÀÖ½À´Ï´Ù.

¿©±â¼­´Â À©µµ¿ì¿¡¼­ ÀÚÁÖ »ç¿ëÇÏ´Â zipÆÄÀÏ·Î ´Ù¿î¹Þ¾Ò½À´Ï´Ù.



¾ÐÃàÀ» Ç®°í Æú´õ¿¡ µé¾î¿Í º¸¸é Âü ¸¹Àº ÆÄÀÏÀÌ ÀÖ½À´Ï´Ù.



PhotoView¸¦ »ç¿ëÇϱâ À§Çؼ­´Â ÀÏ´Ü ¾Èµå·ÎÀ̵å ÇÁ·ÎÁ§Æ®¿¡ PhotoView ÆÐÅ°Áö¸¦ Æ÷ÇÔ½ÃÄÑ¾ß ÇÕ´Ï´Ù.

PhotoView-1.2.3/library/src/main/java Æú´õ °æ·Î¿¡ °¡º¸¸é uk¶ó´Â Æú´õ°¡ º¸ÀÔ´Ï´Ù. ÀÌ Æú´õ¸¦ ¼±ÅÃÇÏ°í Ctrl + C ¸¦ ´­·¯ º¹»ç¸¦ ÇÕ´Ï´Ù.



¾Èµå·ÎÀ̵å ÇÁ·ÎÁ§Æ®¿¡¼­ ¼Ò½ºÄÚµå ÆÐÅ°Áö°¡ µé¾îÀÖ´Â src Æú´õ¸¦ Ŭ¸¯ÇÏ°í Ctrl + V ¸¦ ´©¸¨´Ï´Ù.



Ctrl + V¸¦ ´­·¯ Á¦´ë·Î º¹»ç¸¦ ÇßÀ¸¸é, À§ È­¸éó·³ ¾ø¾ú´ø 4°³ÀÇ ÆÐÅ°Áö°¡ ³ªÅ¸³³´Ï´Ù.



PhotoView¸¦ À§ÇÑ ÆÐÅ°Áö(¼Ò½ºÄÚµå Æ÷ÇÔ) º¹»ç°¡ ³¡³µÀ¸¸é ÀÌÁ¦ ±âÁ¸ÀÇ ÇÁ·ÎÁ§Æ® Äڵ带 ¼öÁ¤ÇØ¾ß ÇÕ´Ï´Ù.

¿¹Á¦´Â °£´ÜÇÑ °ÍÀÌ ÁÁÀ¸´Ï ÇϳªÀÇ ¾×ƼºñƼ¿¡ ÇÊ¿äÇÑ 2°³ÀÇ ÆÄÀÏ(MainActivity.java¿Í activity_main.xml)¸¸ ¼öÁ¤ÇØ º¸°Ú½À´Ï´Ù.

activity_main.xml ÆÄÀÏ
		<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
			xmlns:tools="http://schemas.android.com/tools"
			android:layout_width="match_parent"
			android:layout_height="match_parent"
			android:paddingBottom="@dimen/activity_vertical_margin"
			android:paddingLeft="@dimen/activity_horizontal_margin"
			android:paddingRight="@dimen/activity_horizontal_margin"
			android:paddingTop="@dimen/activity_vertical_margin"
			tools:context="com.example.helloworld.MainActivity" >

			<ImageView
				android:id="@+id/imageView"
				android:layout_width="match_parent"
				android:layout_height="match_parent"
				android:src="@drawable/ic_launcher" />

		</LinearLayout>


ImageView À§Á¬À» Çϳª Ãß°¡ÇÏ°í src´Â ±âº»À¸·Î Á¦°øµÇ´Â ¾Æµå·Îº¸ÀÌ À̹ÌÁö¸¦ »ç¿ëÇßÀ¸¸ç ÀÚ¹ÙÄڵ忡¼­ À̹ÌÁöºä¸¦ ÂüÁ¶Çϱâ À§ÇØ id°ªÀ» ÁöÁ¤Çß½À´Ï´Ù.

MainActivity.java ÆÄÀÏ
		package com.example.helloworld;

		import uk.co.senab.photoview.PhotoViewAttacher;
		import android.os.Bundle;
		import android.support.v7.app.ActionBarActivity;
		import android.widget.ImageView;
		import android.widget.ImageView.ScaleType;

		public class MainActivity extends ActionBarActivity {
			// 1.º¯¼ö¼±¾ð	
			ImageView m_imageView;
			PhotoViewAttacher mAttacher;

			@Override
			protected void onCreate(Bundle savedInstanceState) {
				super.onCreate(savedInstanceState);
				setContentView(R.layout.activity_main);
				
				// 2.ImageView¸¦ ÀÎÀÚ·Î ÇÏ¿© PhotoViewAttacher°´Ã¼¸¦ »ý¼º
				m_imageView = (ImageView) findViewById(R.id.imageView);
				mAttacher = new PhotoViewAttacher(m_imageView);
				// 3.È­¸é¿¡ ²ËÂ÷´Â ¿É¼Ç (¼±ÅûçÇ×)
				mAttacher.setScaleType(ScaleType.FIT_XY);
			}
		}


ImageView, PhotoViewAttacher º¯¼ö¸¦ ¼±¾ðÇÏ°í ImageView¸¦ ±â¹ÝÀ¸·Î ÇÏ´Â PhotoViewAttacher °´Ã¼¸¦ »ý¼ºÇÏ´Â ÇÏ´Â ÄÚµåÀÔ´Ï´Ù.

¸¶Áö¸·¿¡ ÀÖ´Â setScaleType(ScaleType.FIT_XY)´Â À̹ÌÁö°¡ ÀÛÀ» ¶§ À̹ÌÁö Å©±â¸¦ ImageView »çÀÌÁŭ ´Ã¿©ÁÖ´Â ¿ªÇÒÀ» Çϴµ¥

ÇÊ¿äÇÑ °æ¿ì¿¡¸¸ »ç¿ëÇÏ¸é µË´Ï´Ù. (FIT_XY¸»°í ´Ù¸¥ ¿É¼Çµµ °¡´É)

PhotoView ÆÐÅ°Áö¸¦ ÇÁ·ÎÁ§Æ®¿¡ Æ÷ÇÔ½ÃÅ°°í MainActivity.java¿Í activity_main.xml ÆÄÀϱîÁö ÀÛ¼ºÇß´Ù¸é ¸ðµç ÀÛ¾÷ÀÌ ³¡³µ½À´Ï´Ù.

ÀÌÁ¦ ½ÇÇàÇؼ­ Å×½ºÆ®¸¸ Çغ¸¸é µË´Ï´Ù.


 


¼Ò½ºÆÄÀÏÀ» ¿Ã·Á ³õ½À´Ï´Ù. ´Ù¿î¹Þ¾Æ¼­ Å×½ºÆ®ÇØ º¸¼¼¿ä.

PhotoView-master.zip
 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.