안드로이드

나인 패치

liufeier 2021. 10. 26. 10:24
반응형
https://developer.android.com/studio/write/draw9patch?hl=ko

https://github.com/mike-jung/DoItAndroidRev8/tree/master/part2/chapter07/SampleNinePatch/app/src/main/res/drawable
이미지 파일 자료

 

나인 패치(Nine Patch)는 이미지가 늘어나거나 줄어들 때 생기는 이미지 왜곡을 해결하는 방법을 정의하는 것

 

파일 확장자 앞에 '.9'를 붙여야 한다

 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_image_01"
        android:text="SMALL" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_image_01"
        android:text="MEDIUMMEDIUMMEDIUM" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_image_01"
        android:text="LONGLONGLONGLONGLONGLONGLONGLONGLONG" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_image_02"
        android:text="SMALL" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_image_02"
        android:text="MEDIUMMEDIUMMEDIUM" />

    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_image_02"
        android:text="LONGLONGLONGLONGLONGLONGLONGLONGLONG" />
</LinearLayout>

 

 

 

 

 

 

반응형