Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android View setPadding() vs setPaddingRelative()

Based on the Android document which doesn't give much explanation, what's the difference between setPadding() vs setPaddingRelative()?

like image 932
jerrytouille Avatar asked Mar 13 '13 07:03

jerrytouille


People also ask

What is setPaddingRelative?

So when you set padding with setPaddingRelative it changes left and right padding values depending on user's layout direction. Follow this answer to receive notifications.

How do you add padding to a view?

Use the setPadding(left, top, right, bottom) method on the view to set the padding. The integers passed as parameters to this function are the number of pixels (px), which are different from the density-independent pixels (dp or dip).


1 Answers

setPaddingRelative has this code inside:

switch(getResolvedLayoutDirection()) {         case LAYOUT_DIRECTION_RTL:             setPadding(end, top, start, bottom);             break;         case LAYOUT_DIRECTION_LTR:         default:             setPadding(start, top, end, bottom); } 

So when you set padding with setPaddingRelative it changes left and right padding values depending on user's layout direction.

like image 148
Leonidos Avatar answered Oct 01 '22 01:10

Leonidos