@@ -369,10 +369,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
369369 int width = 0 ;
370370 int height = 0 ;
371371
372- int widthMode = MeasureSpec .getMode (widthMeasureSpec );
373- int heightMode = MeasureSpec .getMode (heightMeasureSpec );
374- int widthSize = MeasureSpec .getSize (widthMeasureSpec );
375- int heightSize = MeasureSpec .getSize (heightMeasureSpec );
372+ final int widthMode = MeasureSpec .getMode (widthMeasureSpec );
373+ final int heightMode = MeasureSpec .getMode (heightMeasureSpec );
374+ final int widthSize = MeasureSpec .getSize (widthMeasureSpec );
375+ final int heightSize = MeasureSpec .getSize (heightMeasureSpec );
376376
377377 // Record our dimensions if they are known;
378378 if (widthMode != MeasureSpec .UNSPECIFIED ) {
@@ -416,6 +416,32 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
416416
417417 View [] views = mSortedHorizontalChildren ;
418418 int count = views .length ;
419+
420+ // We need to know our size for doing the correct computation of positioning in RTL mode
421+ if (isLayoutRtl () && (myWidth == -1 || isWrapContentWidth )) {
422+ myWidth = getPaddingStart () + getPaddingEnd ();
423+ final int childWidthMeasureSpec = MeasureSpec .makeMeasureSpec (0 , MeasureSpec .UNSPECIFIED );
424+ for (int i = 0 ; i < count ; i ++) {
425+ View child = views [i ];
426+ if (child .getVisibility () != GONE ) {
427+ LayoutParams params = (LayoutParams ) child .getLayoutParams ();
428+ // Would be similar to a call to measureChildHorizontal(child, params, -1, myHeight)
429+ // but we cannot change for now the behavior of measureChildHorizontal() for
430+ // taking care or a "-1" for "mywidth" so use here our own version of that code.
431+ int childHeightMeasureSpec ;
432+ if (params .width == LayoutParams .MATCH_PARENT ) {
433+ childHeightMeasureSpec = MeasureSpec .makeMeasureSpec (myHeight , MeasureSpec .EXACTLY );
434+ } else {
435+ childHeightMeasureSpec = MeasureSpec .makeMeasureSpec (myHeight , MeasureSpec .AT_MOST );
436+ }
437+ child .measure (childWidthMeasureSpec , childHeightMeasureSpec );
438+
439+ myWidth += child .getMeasuredWidth ();
440+ myWidth += params .leftMargin + params .rightMargin ;
441+ }
442+ }
443+ }
444+
419445 for (int i = 0 ; i < count ; i ++) {
420446 View child = views [i ];
421447 if (child .getVisibility () != GONE ) {
@@ -924,7 +950,7 @@ private View getRelatedView(int[] rules, int relation) {
924950
925951 // Find the first non-GONE view up the chain
926952 while (v .getVisibility () == View .GONE ) {
927- rules = ((LayoutParams ) v .getLayoutParams ()).getRules ();
953+ rules = ((LayoutParams ) v .getLayoutParams ()).getRules (v . getLayoutDirection () );
928954 node = mGraph .mKeyNodes .get ((rules [relation ]));
929955 if (node == null ) return null ;
930956 v = node .view ;
@@ -975,7 +1001,7 @@ private void centerVertical(View child, LayoutParams params, int myHeight) {
9751001 protected void onLayout (boolean changed , int l , int t , int r , int b ) {
9761002 // The layout has actually already been performed and the positions
9771003 // cached. Apply the cached values to the children.
978- int count = getChildCount ();
1004+ final int count = getChildCount ();
9791005
9801006 for (int i = 0 ; i < count ; i ++) {
9811007 View child = getChildAt (i );
0 commit comments