728x90
안녕하세요,
오늘은 ZoomLayout을 활용하여 이미지를 확대/축소하는 예제를 만들어 보도록 하겠습니다.
ZoomLayout은 빠르고 간단하게 확대/축소 및 이동 기능을 추가할 수 있습니다.
먼저, build.gradle(Module: app) 파일에 ZoomLayout 의존성을 추가합니다.
dependencies {
implementation ("com.otaliastudios:zoomlayout:1.9.0")
}
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">
<com.otaliastudios.zoom.ZoomLayout
android:id="@+id/zoom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
<ImageView
android:id="@+id/zoom_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:srcCompat="@android:drawable/btn_star_big_on" />
</com.otaliastudios.zoom.ZoomLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private ZoomLayout zoomLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
zoomLayout = findViewById(R.id.zoom_layout);
// 설정: Zoom 및 이동 활성화
zoomLayout.setMinZoom(1.0f); // 최소 확대 비율
zoomLayout.setMaxZoom(4.0f); // 최대 확대 비율
}
}
시연 영상입니다.
'안드로이드 자바' 카테고리의 다른 글
[Java][Android] Bundle을 활용해 액티비티 간 데이터 전달하기 (0) | 2025.01.05 |
---|---|
[Java][Android] Handler를 활용한 텍스트 자동 타이핑 애니메이션 (2) | 2025.01.01 |
[Java][Android] VelocityTracker을 사용한 드래그 속도에 따른 동작 변화 (2) | 2024.12.30 |
[Java][Android] DragEventListener를 사용해 드래그 앤 드롭 구현하기 (0) | 2024.12.26 |
[Java][Android] TransitionManager로 뷰 크기와 투명도 애니메이션 구현하기 (0) | 2024.12.24 |