programing

뷰의 패딩과 여백의 차이점

new-time 2020. 2. 9. 19:59
반응형

뷰의 패딩과 여백의 차이점


뷰의 여백과 패딩의 차이점은 무엇입니까?


 

패딩

의 의미를 기억할 수 있도록

두꺼운 코튼 패딩

이 많은 큰 코트를 생각 합니다. 나는 내 코트 안에 있지만 나와 패딩 코트는 함께 있습니다. 우리는 하나의 단위입니다.그러나

마진

을 기억하기 위해 , "

저기, 약간의 마진을 줘!

" 라고 생각 합니다. 내 안락 지대-내 여백에 오지 마십시오.더 명확하게하기 위해 다음은 패딩과 여백에 대한 그림입니다

TextView

.

여기에 이미지 설명을 입력하십시오

위 이미지의 xml 레이아웃

<?xml version="1.0" encoding="utf-8"?> <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:textColor="#000000" 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:textColor="#000000" 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:textColor="#000000" 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:textColor="#000000" 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:textColor="#000000" 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:textColor="#000000" 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:textColor="#000000" 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:textColor="#000000" android:text="TextView no padding no margin" android:textSize="20sp" />  </LinearLayout> 

관련


패딩

은 경계와 실제보기의 내용 사이의 경계 내부 공간입니다. 패딩은 내용을 완전히 둘러 쌉니다. 위쪽, 아래쪽, 오른쪽 및 왼쪽에 패딩이 있습니다 (독립적 일 수 있음).

여백

은 테두리와이 뷰 옆의 다른 요소 사이의 경계 외부 공간입니다. 이미지에서 여백은 전체 객체 외부의 회색 영역입니다. 패딩과 마찬가지로 여백은 내용 주위를 완전히 돌아갑니다. 위쪽, 아래쪽, 오른쪽 및 왼쪽에 여백이 있습니다.이미지에 1000 개 이상의 단어가 표시됩니다 (

Margin Vs Padding-CSS 속성

에서 추출 ).

대체 텍스트


패딩이 뷰 내부에 있습니다.여백은보기 외부에 있습니다.이 차이는 배경 또는 크기 속성과 관련이있을 수 있습니다.


패딩이 뷰 내에 있고 여백이 밖에 있습니다. 모든 뷰에서 패딩을 사용할 수 있습니다. 보기에 따라 패딩과 여백 사이에 시각적 차이가있을 수도 있고 없을 수도 있습니다.예를 들어, 버튼의 경우, 특징적인 버튼 배경 이미지에는 여백이 아닌 패딩이 포함됩니다. 다시 말해서, 패딩을 더 추가하면 버튼이 시각적으로 더 크게 보이고, 여백을 더 추가하면 버튼과 다음 컨트롤 사이의 간격이 더 넓어집니다.들면

TextView

S 한편, 패딩 마진의 시각적 효과는 동일하다.여백을 사용할 수 있는지 여부는 뷰 자체가 아니라 뷰 컨테이너에 의해 결정됩니다. 에서

LinearLayout

여백에, 지원

AbsoluteLayout

없음 - (지금은 사용되지 않는 것으로 간주).


아래 이미지는 패딩과 여백을 이해하게합니다.

여기에 이미지 설명을 입력하십시오


패딩은 위젯과 위젯 원래 프레임 사이의 공간을 의미합니다. 그러나 여백은 위젯의 원래 프레임과 다른 위젯의 프레임 경계 사이의 공간입니다.

여기에 이미지 설명을 입력하십시오

.


패딩은 테두리와 실제 이미지 또는 셀 내용 사이의 테두리 내부 공간입니다. 여백은 테두리와이 개체 옆의 다른 요소 사이의 경계 외부 공간입니다.


패딩이나 여백만으로도 같은 결과를 얻을 수 있습니다. 예 :View X에 View Y가 포함되어 있다고 가정하십시오 (일명 : View Y는 View X 안에 있음).-여백이 30 인 뷰 Y 또는 패딩이 30 인 뷰 X는 동일한 결과를 얻습니다. 뷰 Y의 오프셋은 30입니다.


Padding
Padding is inside of a View.For example if you give android:paddingLeft=20dp, then the items inside the view will arrange with 20dp width from left.You can also use paddingRight, paddingBottom, paddingTop which are to give padding from right, bottom and top respectively.

Margin
Margin is outside of a View. For example if you give android:marginLeft=20dp , then the view will be arranged after 20dp from left.


Let's just suppose you have a button in a view and the size of the view is 200 by 200, and the size of the button is 50 by 50, and the button title is HT. Now the difference between margin and padding is, you can set the margin of the button in the view, for example 20 from the left, 20 from the top, and padding will adjust the text position in the button or text view etc. for example, padding value is 20 from the left, so it will adjust the position of the text.


Margin refers to the extra space outside of an element. Padding refers to the extra space within an element. The margin is the extra space around the control. The padding is extra space inside the control.

It's hard to see the difference with margin and padding with a white fill, but with a colored fill you can see it fine.


In simple words:
padding changes the size of the box (with something).
margin changes the space between different boxes


In addition to all the correct answers above, one other difference is that padding increases the clickable area of a view, whereas margins do not. This is useful if you have a smallish clickable image but want to make the click handler forgiving.

For eg, see this image of my layout with an ImageView (the Android icon) where I set the paddingBotton to be 100dp (the image is the stock launcher mipmap ic_launcher). With the attached click handler I was able to click way outside and below the image and still register a click.

여기에 이미지 설명을 입력하십시오


In simple words:

  1. Padding - creates space inside the view's border.
  2. 여백-보기 테두리 외부에 공간을 만듭니다.

참고 URL :

https://stackoverflow.com/questions/4619899/difference-between-a-views-padding-and-margin



도움이 되겠다면 ↓↓↓ 배너 한번만 클릭 해주시면 감사합니다 ^^

반응형