Skip to content

Commit b6a45cb

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Make RelativeLayout aware of layout direction"
2 parents 9ba15a9 + f443f98 commit b6a45cb

File tree

5 files changed

+257
-30
lines changed

5 files changed

+257
-30
lines changed

api/current.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,16 @@ package android {
607607
field public static final int layout_above = 16843140; // 0x1010184
608608
field public static final int layout_alignBaseline = 16843142; // 0x1010186
609609
field public static final int layout_alignBottom = 16843146; // 0x101018a
610+
field public static final int layout_alignEnd = 16843706; // 0x10103ba
610611
field public static final int layout_alignLeft = 16843143; // 0x1010187
611612
field public static final int layout_alignParentBottom = 16843150; // 0x101018e
613+
field public static final int layout_alignParentEnd = 16843708; // 0x10103bc
612614
field public static final int layout_alignParentLeft = 16843147; // 0x101018b
613615
field public static final int layout_alignParentRight = 16843149; // 0x101018d
616+
field public static final int layout_alignParentStart = 16843707; // 0x10103bb
614617
field public static final int layout_alignParentTop = 16843148; // 0x101018c
615618
field public static final int layout_alignRight = 16843145; // 0x1010189
619+
field public static final int layout_alignStart = 16843705; // 0x10103b9
616620
field public static final int layout_alignTop = 16843144; // 0x1010188
617621
field public static final int layout_alignWithParentIfMissing = 16843154; // 0x1010192
618622
field public static final int layout_below = 16843141; // 0x1010185
@@ -634,8 +638,10 @@ package android {
634638
field public static final int layout_rowSpan = 16843644; // 0x101037c
635639
field public static final int layout_scale = 16843155; // 0x1010193
636640
field public static final int layout_span = 16843085; // 0x101014d
641+
field public static final int layout_toEndOf = 16843704; // 0x10103b8
637642
field public static final int layout_toLeftOf = 16843138; // 0x1010182
638643
field public static final int layout_toRightOf = 16843139; // 0x1010183
644+
field public static final int layout_toStartOf = 16843703; // 0x10103b7
639645
field public static final int layout_weight = 16843137; // 0x1010181
640646
field public static final int layout_width = 16842996; // 0x10100f4
641647
field public static final int layout_x = 16843135; // 0x101017f
@@ -25096,9 +25102,12 @@ package android.view {
2509625102
ctor public ViewGroup.MarginLayoutParams(int, int);
2509725103
ctor public ViewGroup.MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams);
2509825104
ctor public ViewGroup.MarginLayoutParams(android.view.ViewGroup.LayoutParams);
25105+
method public int getLayoutDirection();
2509925106
method public int getMarginEnd();
2510025107
method public int getMarginStart();
25108+
method protected boolean isLayoutRtl();
2510125109
method public boolean isMarginRelative();
25110+
method public void setLayoutDirection(int);
2510225111
method public void setMargins(int, int, int, int);
2510325112
field public int bottomMargin;
2510425113
field public int endMargin;
@@ -28399,19 +28408,25 @@ package android.widget {
2839928408
field public static final int ABOVE = 2; // 0x2
2840028409
field public static final int ALIGN_BASELINE = 4; // 0x4
2840128410
field public static final int ALIGN_BOTTOM = 8; // 0x8
28411+
field public static final int ALIGN_END = 19; // 0x13
2840228412
field public static final int ALIGN_LEFT = 5; // 0x5
2840328413
field public static final int ALIGN_PARENT_BOTTOM = 12; // 0xc
28414+
field public static final int ALIGN_PARENT_END = 21; // 0x15
2840428415
field public static final int ALIGN_PARENT_LEFT = 9; // 0x9
2840528416
field public static final int ALIGN_PARENT_RIGHT = 11; // 0xb
28417+
field public static final int ALIGN_PARENT_START = 20; // 0x14
2840628418
field public static final int ALIGN_PARENT_TOP = 10; // 0xa
2840728419
field public static final int ALIGN_RIGHT = 7; // 0x7
28420+
field public static final int ALIGN_START = 18; // 0x12
2840828421
field public static final int ALIGN_TOP = 6; // 0x6
2840928422
field public static final int BELOW = 3; // 0x3
2841028423
field public static final int CENTER_HORIZONTAL = 14; // 0xe
2841128424
field public static final int CENTER_IN_PARENT = 13; // 0xd
2841228425
field public static final int CENTER_VERTICAL = 15; // 0xf
28426+
field public static final int END_OF = 17; // 0x11
2841328427
field public static final int LEFT_OF = 0; // 0x0
2841428428
field public static final int RIGHT_OF = 1; // 0x1
28429+
field public static final int START_OF = 16; // 0x10
2841528430
field public static final int TRUE = -1; // 0xffffffff
2841628431
}
2841728432

core/java/android/view/ViewGroup.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5504,13 +5504,17 @@ public static class MarginLayoutParams extends ViewGroup.LayoutParams {
55045504

55055505
/**
55065506
* The default start and end margin.
5507+
* @hide
55075508
*/
5508-
static private final int DEFAULT_RELATIVE = Integer.MIN_VALUE;
5509+
public static final int DEFAULT_RELATIVE = Integer.MIN_VALUE;
55095510

55105511
private int initialLeftMargin;
55115512
private int initialRightMargin;
55125513

5513-
private int layoutDirection;
5514+
private static int LAYOUT_DIRECTION_UNDEFINED = -1;
5515+
5516+
// Layout direction undefined by default
5517+
private int layoutDirection = LAYOUT_DIRECTION_UNDEFINED;
55145518

55155519
/**
55165520
* Creates a new set of layout parameters. The values are extracted from
@@ -5553,9 +5557,6 @@ public MarginLayoutParams(Context c, AttributeSet attrs) {
55535557
initialLeftMargin = leftMargin;
55545558
initialRightMargin = rightMargin;
55555559

5556-
// LTR by default
5557-
layoutDirection = View.LAYOUT_DIRECTION_LTR;
5558-
55595560
a.recycle();
55605561
}
55615562

@@ -5585,7 +5586,7 @@ public MarginLayoutParams(MarginLayoutParams source) {
55855586
this.initialLeftMargin = source.leftMargin;
55865587
this.initialRightMargin = source.rightMargin;
55875588

5588-
this.layoutDirection = source.layoutDirection;
5589+
setLayoutDirection(source.layoutDirection);
55895590
}
55905591

55915592
/**
@@ -5688,19 +5689,41 @@ public int getMarginEnd() {
56885689
* @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart
56895690
* @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd
56905691
*
5691-
* @return true if either marginStart or marginEnd has been set
5692+
* @return true if either marginStart or marginEnd has been set.
56925693
*/
56935694
public boolean isMarginRelative() {
56945695
return (startMargin != DEFAULT_RELATIVE) || (endMargin != DEFAULT_RELATIVE);
56955696
}
56965697

5698+
/**
5699+
* Set the layout direction
5700+
* @param layoutDirection the layout direction.
5701+
* Should be either {@link View#LAYOUT_DIRECTION_LTR}
5702+
* or {@link View#LAYOUT_DIRECTION_RTL}.
5703+
*/
5704+
public void setLayoutDirection(int layoutDirection) {
5705+
if (layoutDirection != View.LAYOUT_DIRECTION_LTR &&
5706+
layoutDirection != View.LAYOUT_DIRECTION_RTL) return;
5707+
this.layoutDirection = layoutDirection;
5708+
}
5709+
5710+
/**
5711+
* Retuns the layout direction. Can be either {@link View#LAYOUT_DIRECTION_LTR} or
5712+
* {@link View#LAYOUT_DIRECTION_RTL}.
5713+
*
5714+
* @return the layout direction.
5715+
*/
5716+
public int getLayoutDirection() {
5717+
return layoutDirection;
5718+
}
5719+
56975720
/**
56985721
* This will be called by {@link android.view.View#requestLayout()}. Left and Right margins
56995722
* may be overridden depending on layout direction.
57005723
*/
57015724
@Override
57025725
public void onResolveLayoutDirection(int layoutDirection) {
5703-
this.layoutDirection = layoutDirection;
5726+
setLayoutDirection(layoutDirection);
57045727

57055728
if (!isMarginRelative()) return;
57065729

@@ -5717,6 +5740,10 @@ public void onResolveLayoutDirection(int layoutDirection) {
57175740
}
57185741
}
57195742

5743+
protected boolean isLayoutRtl() {
5744+
return (layoutDirection == View.LAYOUT_DIRECTION_RTL);
5745+
}
5746+
57205747
/**
57215748
* @hide
57225749
*/

0 commit comments

Comments
 (0)