jerrytouille
jerrytouille

Reputation: 1238

Android View setPadding() vs setPaddingRelative()

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

Upvotes: 50

Views: 18012

Answers (1)

Leonidos
Leonidos

Reputation: 10518

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.

Upvotes: 70

Related Questions