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>
댓글 입력