Android beginner difference between padding and margin
android
Solution
`Padding` is for inside/within components. Eg. `TextView` , `Button`, `EditText` etc. Eg. space between the Text and Border
`Margin` is to be applied for the on-outside of the components. Eg. space between left edge of the screen and border of your component
Visual representation is great in : Difference between a View's Padding and Margin
With `Padding`, i have seen a difference in 2.2, 2.3 and say 4.3, 4.4 in such cases:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="ASDFGHJKL" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:text="@string/hello_world" />
</RelativeLayout>
Also, check the use of dimens: http://developer.android.com/guide/topics/resources/more-resources.html
Problem
I have referred questions on SO. ALso checked an answer: Padding is the space inside the border, between the border and the actual view's content. Note that padding goes completely around the content: there is padding on the top, bottom, right and left sides (which can be independent). Margins are the spaces outside the border, between the border and the other elements next to this view. In the image, the margin is the grey area outside the entire object. Note that, like the padding, the margin goes completely around the content: there are margins on the top, bottom, right, and left sides. Also, more on padding and margins from: http://developer.android.com/reference/android/view/View.html http://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html But what is the difference fundamentally between padding and margins ? Would the behaviour differ depending on O.S. and devices? I have a normal, simple layout. No problem with code, have used layout folders - layout and layout-sw600dp plus drawables-4dpi. Can't make layout without margin or padding, which one is more appropriate?