본문 바로가기
안드로이드

[Android] FAB image size 조정하기

by Banlim 2020. 12. 2.

[잊어버릴까봐 기록]

 

Floating Action Button 안에 이미지를 넣었는데, 이 때 이미지가 너무 작게 나와 잘 보이지 않았다.

따라서, FAB 안에 원하는 이미지를 삽입할 때 이미지 사이즈 조정하는 방법을 찾아보았다.

 

아래 코드에서 중요한 건 app:maxImageSize 이다.

maxImageSize 부분을 적당히 조절하여 이미지 사이즈를 원하는대로 조정할 수 있다.

 

fragment_fabtest.xml

<com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start|bottom"
            android:layout_marginLeft="30dp"
            android:layout_marginBottom="40dp"
            android:background="@android:color/transparent"
            android:elevation="0dp"
            app:maxImageSize="25dp"
            android:src="@drawable/custom_image"
            app:elevation="0dp"
            app:fabSize="normal" />

 

+) 추가로, fabSize는 mini와 normal이 있다. 이 사이즈는 이미지 사이즈를 조정하는 것이 아닌 FAB 자체 사이즈(동그라미 사이즈)를 조정한다.

 

이 때, mini, normal 둘 다 사이즈가 애매할 수 있다. FAB 자체 사이즈를 조절하고 싶을 때에는,

app:fabCustomSize="75dp"

위와 같은 코드를 통해 사이즈를 늘리거나 줄일 수 있다.