Browse Source

FlowLayout.java 修改

niusongtao@dl-cg.com 5 years ago
parent
commit
4f5807a3c2

+ 41 - 1
base_library/src/main/java/com/mgtech/base_library/custom/FlowLayout.java

@@ -67,6 +67,44 @@ public class FlowLayout extends ViewGroup {
     /**
     /**
      * 分行:遍历所有的子View,判断哪几个子View在同一行(排座位表)
      * 分行:遍历所有的子View,判断哪几个子View在同一行(排座位表)
      */
      */
+
+
+    /**
+     * 获取测量大小
+     */
+    private int getDefaultHeight(int measureSpec) {
+        int result;
+        int specMode = MeasureSpec.getMode(measureSpec);
+        int specSize = MeasureSpec.getSize(measureSpec);
+        if (specMode == MeasureSpec.EXACTLY) {
+            result = specSize;//确切大小,所以将得到的尺寸给view
+        } else if (specMode == MeasureSpec.AT_MOST) {
+            result = 0;
+        } else {
+            result = 0;
+        }
+        return result;
+    }
+
+    /**
+     * 获取测量大小
+     */
+    private int getDefaultWidth(int measureSpec) {
+        int result;
+        int specMode = MeasureSpec.getMode(measureSpec);
+        int specSize = MeasureSpec.getSize(measureSpec);
+        if (specMode == MeasureSpec.EXACTLY) {
+            result = specSize;//确切大小,所以将得到的尺寸给view
+        } else if (specMode == MeasureSpec.AT_MOST) {
+            result = MeasureSpec.AT_MOST;
+        } else {
+            result = MeasureSpec.AT_MOST;
+        }
+        return result;
+    }
+
+
+
     @Override
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
 
 
@@ -113,7 +151,9 @@ public class FlowLayout extends ViewGroup {
         height += (lineList.size()-1)*verticalSpacing;//最后加上所有的行间距
         height += (lineList.size()-1)*verticalSpacing;//最后加上所有的行间距
 
 
         //设置当前控件的宽高,或者向父VIew申请宽高
         //设置当前控件的宽高,或者向父VIew申请宽高
-        setMeasuredDimension(width, height);
+//        setMeasuredDimension(width, height);
+
+        setMeasuredDimension(width, Math.max(getDefaultHeight(heightMeasureSpec),height));
     }
     }
     /**
     /**
      * 去摆放所有的子View,让每个人真正的坐到自己的位置上
      * 去摆放所有的子View,让每个人真正的坐到自己的位置上