Skip to content

Commit 3bef5e9

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Fix View padding resolution"
2 parents 0c245fb + 509708d commit 3bef5e9

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

core/java/android/view/View.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,13 +3093,13 @@ public void onClick(View v) {
30933093
setBackgroundDrawable(background);
30943094
}
30953095

3096-
mUserPaddingRelative = (startPadding >= 0 || endPadding >= 0);
3097-
30983096
// Cache user padding as we cannot fully resolve padding here (we dont have yet the resolved
30993097
// layout direction). Those cached values will be used later during padding resolution.
31003098
mUserPaddingStart = startPadding;
31013099
mUserPaddingEnd = endPadding;
31023100

3101+
updateUserPaddingRelative();
3102+
31033103
if (padding >= 0) {
31043104
leftPadding = padding;
31053105
topPadding = padding;
@@ -3146,6 +3146,10 @@ public void onClick(View v) {
31463146
computeOpaqueFlags();
31473147
}
31483148

3149+
private void updateUserPaddingRelative() {
3150+
mUserPaddingRelative = (mUserPaddingStart >= 0 || mUserPaddingEnd >= 0);
3151+
}
3152+
31493153
/**
31503154
* Non-public constructor for use in testing
31513155
*/
@@ -9644,6 +9648,8 @@ private void resolveLayoutDirectionIfNeeded() {
96449648
// Set to resolved
96459649
mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED;
96469650
onResolvedLayoutDirectionChanged();
9651+
// Resolve padding
9652+
resolvePadding();
96479653
}
96489654

96499655
/**
@@ -9698,7 +9704,11 @@ public void resolvePadding() {
96989704

96999705
mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom;
97009706

9701-
recomputePadding();
9707+
if(isPaddingRelative()) {
9708+
setPaddingRelative(mUserPaddingStart, mPaddingTop, mUserPaddingEnd, mUserPaddingBottom);
9709+
} else {
9710+
recomputePadding();
9711+
}
97029712
onPaddingChanged(resolvedLayoutDirection);
97039713
}
97049714

@@ -12233,15 +12243,20 @@ public Drawable getBackground() {
1223312243
* @param bottom the bottom padding in pixels
1223412244
*/
1223512245
public void setPadding(int left, int top, int right, int bottom) {
12236-
boolean changed = false;
12237-
12246+
mUserPaddingStart = -1;
12247+
mUserPaddingEnd = -1;
1223812248
mUserPaddingRelative = false;
1223912249

12250+
internalSetPadding(left, top, right, bottom);
12251+
}
12252+
12253+
private void internalSetPadding(int left, int top, int right, int bottom) {
1224012254
mUserPaddingLeft = left;
1224112255
mUserPaddingRight = right;
1224212256
mUserPaddingBottom = bottom;
1224312257

1224412258
final int viewFlags = mViewFlags;
12259+
boolean changed = false;
1224512260

1224612261
// Common case is there are no scroll bars.
1224712262
if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) {
@@ -12310,18 +12325,17 @@ public void setPadding(int left, int top, int right, int bottom) {
1231012325
* @param bottom the bottom padding in pixels
1231112326
*/
1231212327
public void setPaddingRelative(int start, int top, int end, int bottom) {
12313-
mUserPaddingRelative = true;
12314-
1231512328
mUserPaddingStart = start;
1231612329
mUserPaddingEnd = end;
12330+
mUserPaddingRelative = true;
1231712331

1231812332
switch(getResolvedLayoutDirection()) {
1231912333
case LAYOUT_DIRECTION_RTL:
12320-
setPadding(end, top, start, bottom);
12334+
internalSetPadding(end, top, start, bottom);
1232112335
break;
1232212336
case LAYOUT_DIRECTION_LTR:
1232312337
default:
12324-
setPadding(start, top, end, bottom);
12338+
internalSetPadding(start, top, end, bottom);
1232512339
}
1232612340
}
1232712341

0 commit comments

Comments
 (0)