@@ -65,15 +65,14 @@ public PseudoGridView(Context context, AttributeSet attrs) {
6565
6666 @ Override
6767 protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
68- int widthMode = MeasureSpec .getMode (widthMeasureSpec );
69- if (widthMode == MeasureSpec .UNSPECIFIED ) {
68+ if (MeasureSpec .getMode (widthMeasureSpec ) == MeasureSpec .UNSPECIFIED ) {
7069 throw new UnsupportedOperationException ("Needs a maximum width" );
7170 }
7271 int width = MeasureSpec .getSize (widthMeasureSpec );
7372
7473 int childWidth = (width - (mNumColumns - 1 ) * mHorizontalSpacing ) / mNumColumns ;
7574 int childWidthSpec = MeasureSpec .makeMeasureSpec (childWidth , MeasureSpec .EXACTLY );
76- int childHeightSpec = MeasureSpec .makeMeasureSpec ( 0 , MeasureSpec . UNSPECIFIED ) ;
75+ int childHeightSpec = MeasureSpec .UNSPECIFIED ;
7776 int totalHeight = 0 ;
7877 int children = getChildCount ();
7978 int rows = (children + mNumColumns - 1 ) / mNumColumns ;
@@ -89,7 +88,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
8988 int maxHeightSpec = MeasureSpec .makeMeasureSpec (maxHeight , MeasureSpec .EXACTLY );
9089 for (int i = startOfRow ; i < endOfRow ; i ++) {
9190 View child = getChildAt (i );
92- child .measure (childWidthSpec , maxHeightSpec );
91+ if (child .getMeasuredHeight () != maxHeight ) {
92+ child .measure (childWidthSpec , maxHeightSpec );
93+ }
9394 }
9495 totalHeight += maxHeight ;
9596 if (row > 0 ) {
@@ -102,21 +103,29 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
102103
103104 @ Override
104105 protected void onLayout (boolean changed , int l , int t , int r , int b ) {
106+ boolean isRtl = isLayoutRtl ();
105107 int children = getChildCount ();
106108 int rows = (children + mNumColumns - 1 ) / mNumColumns ;
107109 int y = 0 ;
108110 for (int row = 0 ; row < rows ; row ++) {
109- int x = 0 ;
111+ int x = isRtl ? getWidth () : 0 ;
110112 int maxHeight = 0 ;
111113 int startOfRow = row * mNumColumns ;
112114 int endOfRow = Math .min (startOfRow + mNumColumns , children );
113115 for (int i = startOfRow ; i < endOfRow ; i ++) {
114116 View child = getChildAt (i );
115117 int width = child .getMeasuredWidth ();
116118 int height = child .getMeasuredHeight ();
119+ if (isRtl ) {
120+ x -= width ;
121+ }
117122 child .layout (x , y , x + width , y + height );
118123 maxHeight = Math .max (maxHeight , height );
119- x += width + mHorizontalSpacing ;
124+ if (isRtl ) {
125+ x -= mHorizontalSpacing ;
126+ } else {
127+ x += width + mHorizontalSpacing ;
128+ }
120129 }
121130 y += maxHeight ;
122131 if (row > 0 ) {
0 commit comments