뷰에서 Padding하고 Margin의 차이가 뭔가요?

조회수 14266회

뷰에서 Padding하고 Margin의 차이가 뭔가요?

1 답변

  • 좋아요

    2

    싫어요
    채택 취소하기

    1

    마진은 뷰와 부모 사이에 적용되며 패딩은 뷰와 내용물 사이에 적용됩니다. 뷰의 입장에서 볼 때 마진은 바깥 여백이고 패딩은 안쪽 여백입니다. 딩은 뷰의 내부이므로 크기에 포함되지만 마진은 그렇지 않다는 점에서 다릅니다. 또한 이름으로부터 유추할 수 있듯이 두 속성은 소속도 틀린데 패딩은 뷰 자체의 속성이지만 마진은 레이아웃의 속성입니다.

    몇 가지 예제를 만들어 보면 두 속성의 차이점을 직관적으로 알 수 있을 겁니다. 밑의 예제를 참고하세요.

    1

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="#c5e1b0"
            android:text="TextView margin only"
            android:textSize="20sp" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="#f6c0c0"
            android:text="TextView margin only"
            android:textSize="20sp" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#c5e1b0"
            android:padding="10dp"
            android:text="TextView padding only"
            android:textSize="20sp" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#f6c0c0"
            android:padding="10dp"
            android:text="TextView padding only"
            android:textSize="20sp" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="#c5e1b0"
            android:padding="10dp"
            android:text="TextView padding and margin"
            android:textSize="20sp" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="#f6c0c0"
            android:padding="10dp"
            android:text="TextView padding and margin"
            android:textSize="20sp" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#c5e1b0"
            android:text="TextView no padding no margin"
            android:textSize="20sp" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#f6c0c0"
            android:text="TextView no padding no margin"
            android:textSize="20sp" />
    
    </LinearLayout>
    

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)