About padding and margin in android

  • Replies:3
  • OpenNot stickiedUnanswered
  • Forum posts: 2

Mar 29, 2016 5:50:22 PM via Website

why cant the padding in android be more optimized?
instead of writting code like this
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"

why cant we write like this
android:padding="8dp 8dp 8dp 8dp" // "top right bottom left"

In the similar way to margin in android
android:layout_margin="5dp 5dp 9dp 6dp" // "top right bottom left"

:)

  • Forum posts: 270

Mar 29, 2016 10:14:32 PM via Website

Android Studio has Layout Editor, where you can choose ALL for margins and paddings:
image

  • Forum posts: 2

Mar 30, 2016 1:27:33 PM via Website

Thank you Vladimir all is for giving value 8dp to all sides if I need "8dp 7dp 16dp 10dp" why can't I achieve in this manner.☺️

  • Forum posts: 207

Mar 31, 2016 9:37:25 AM via Website

why cant we write like this
android:padding="8dp 8dp 8dp 8dp" // "top right bottom left"

In the similar way to margin in android
android:layout_margin="5dp 5dp 9dp 6dp" // "top right bottom left"

you can use this in tun time. Let sat yous have a textview which id is @+id/text than

text.setpadding(left,right,top,bottom) but not in xml file.

same for margin you can use.

cheers