Android View setPadding() vs setPaddingRelative()

jerrytouille picture jerrytouille · Mar 13, 2013 · Viewed 13.4k times · Source

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

Answer

Leonidos picture Leonidos · Mar 13, 2013

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.