본문 바로가기
IT

안드로이드 확대 축소 기능 넣기

by 달남 2019. 6. 6.

1. build.gradle ( project )

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
    repositories { 
        google() 
        jcenter() 
         
    } 
    dependencies { 
        classpath 'com.android.tools.build:gradle:3.4.1' 
         
        // NOTE: Do not place your application dependencies here; they belong 
        // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
        google() 
        jcenter() 
        maven { url "https://jitpack.io" } 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

2. build.gradle ( module app )

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 29 
    buildToolsVersion "29.0.0" 
    defaultConfig { 
        applicationId "com.example.one" 
        minSdkVersion 15 
        targetSdkVersion 29 
        versionCode 1 
        versionName "1.0" 
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
        release { 
            minifyEnabled false 
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 
        } 
    } 
} 

dependencies { 
    implementation fileTree(dir: 'libs', include: ['*.jar']) 
    implementation 'androidx.appcompat:appcompat:1.0.2' 
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'androidx.test:runner:1.2.0' 
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 

    implementation 'com.github.chrisbanes:PhotoView:2.1.3' 
}


3. activity_main.xml 추가 

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photoView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

4.이미지 화일 넣기

 

5. MainActivity.java 

package com.example.one; 

import androidx.appcompat.app.AppCompatActivity; 

import android.content.pm.ActivityInfo; 
import android.os.Bundle; 
import com.github.chrisbanes.photoview.PhotoView; 

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
        setContentView(R.layout.activity_main); 

        PhotoView photoView = findViewById(R.id.photoView); 
        photoView.setImageResource(R.drawable.map); 

    } 
}

순서대로 하기만 하면 잘 작동 하네요

 

출처:

https://github.com/chrisbanes/PhotoView

댓글