은근한

Android ImageView Zoom 본문

카테고리 없음

Android ImageView Zoom

EsJoo 2014. 10. 5. 22:14

PhotoView.zip


우선 첨부파일에 있는 라이브러리 파일을 받으신후에 Import를 해줍니다.





제가 패키지를 만들어서 그냥 import 시켰습니다.


라이브러리 파일을 하나하나 본것 이아니여서.. 그냥 쓰는걸로..


ㅜㅜ 안쓰는 파일들은 따로 정리하실분은 하셔도 됩니다.


여기서 쓰는 파일은 PhotoViewAttacher 입니다.


사용 방법은 코드에 있지만


PhotoViewAttacher의 클래스를 인스턴스 변수로 선언해줍니다.


코드상에서는 저는 PhtoViewAttacher mAttacher; 로 되어 있네요


간단하게


PhotoViewAttacher mAttacher = new PhotoViewAttacher(ImageView name);


객체를 생성할때 생성자 초기화를 ImageView로 해주시면됩니다.


저는 NetworkImageView 를 썼습니다. netimg로 변수가 되어 있네요.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package android.app.image_process;
 
import android.app.Activity;
import android.app.hairstyle.R;
import android.app.networkimage.VolleySingleton;
 
import android.app.zoom.PhotoViewAttacher;
import android.content.Intent;
import android.os.Bundle;
 
import android.view.Menu;
import android.view.MenuItem;
 
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
 
public class Image_click extends Activity {
    
    
    PhotoViewAttacher mAttacher;
    private ImageLoader mImageLoader;
    
    private String url;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_click);
        
        Intent intent = getIntent();
        url = intent.getExtras().getString("url");
        
        
        mImageLoader = VolleySingleton.getInstance(Image_click.this).getImageLoader();
        NetworkImageView netimg = (NetworkImageView)findViewById(R.id.click_image);
        netimg.setImageUrl(url, mImageLoader);
        
        //Zoom Library 사용 할시!  위의 문장들은 네트워크 이미지뷰를 쓴다고 선언한것입니다.
        mAttacher = new PhotoViewAttacher(netimg);
        
 
 
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.image_click, menu);
        return true;
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}