본문 바로가기

Android

Android] ImageButton 이미지 크기 조절

ImageButton을 생성하고 버튼의 이미지를 설정할 때 이미지가 버튼의 크기보다 큰 경우에 이미지가 전체가 아니라 일부만 짤려서 보이는 경우가 발생한다

 

 

<ImageButton
    android:layout_width="250dp"
    android:layout_height="250dp"
    android:src="@drawable/image"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

이렇게 이미지가 짤려서 나올 때는

 

android:scaleType = "  "

android:padding = "  "

 

위의 코드를 통해 이미지를 조절하면 됩니다.

 

ex) 이미지를 버튼에 딱 맞게 조절

 


android:scaleType="centerCrop"
android:padding="0dp"

 

ex)이미지 버튼의 중앙에 위치하게 조절

 


android:scaleType="fitCenter"
android:padding="10dp"



Calendar
«   2025/03   »
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
Tags
더보기
Archives
Visits
Today
Yesterday