Mercurial > dwindows
comparison android/DWindows.kt @ 2553:2b4f2929408e
Android: Fix issue with specifying static sizes... still some issues.
Needed to set the width and height DURING creation of LayoutParams.
Some android controls still don't layout properly when forcing sizes.
So change to -1 (auto size) in dwtest to work around it for now.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 15 May 2021 20:46:17 +0000 |
parents | 303f544d14fa |
children | 4c75fb6089a9 |
comparison
equal
deleted
inserted
replaced
2552:303f544d14fa | 2553:2b4f2929408e |
---|---|
949 box = sv.getChildAt(0) as LinearLayout | 949 box = sv.getChildAt(0) as LinearLayout |
950 } | 950 } |
951 } | 951 } |
952 | 952 |
953 if (box != null) { | 953 if (box != null) { |
954 if ((item is LinearLayout) or (item is ScrollView)) { | 954 var weight: Float = 1F |
955 | |
956 // If it is a box, match parent based on direction | |
957 if ((item is LinearLayout) || (item is ScrollView)) { | |
955 if (box.orientation == LinearLayout.VERTICAL) { | 958 if (box.orientation == LinearLayout.VERTICAL) { |
956 if (hsize != 0) { | 959 if (hsize != 0) { |
957 w = LinearLayout.LayoutParams.MATCH_PARENT | 960 w = LinearLayout.LayoutParams.MATCH_PARENT |
958 } | 961 } |
959 } else { | 962 } else { |
960 if (vsize != 0) { | 963 if (vsize != 0) { |
961 h = LinearLayout.LayoutParams.MATCH_PARENT | 964 h = LinearLayout.LayoutParams.MATCH_PARENT |
962 } | 965 } |
963 } | 966 } |
964 } | |
965 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h) | |
966 | |
967 // If it isn't a box... set or calculate the size as needed | 967 // If it isn't a box... set or calculate the size as needed |
968 if (item !is LinearLayout) { | 968 } else { |
969 if(width != -1 || height != -1) { | 969 if(width != -1 || height != -1) { |
970 item.measure(0, 0) | 970 item.measure(0, 0) |
971 } | 971 } |
972 if(width > 0) { | 972 if(hsize == 0) { |
973 w = width | 973 if (width > 0) { |
974 } else if (width == -1) { | 974 w = width |
975 w = item.getMeasuredWidth() | 975 } |
976 } | 976 } else { |
977 if(height > 0) { | 977 if (width > 0) { |
978 h = height | 978 weight = width.toFloat() |
979 } else if(height == -1) { | 979 } else if (width == -1) { |
980 h = item.getMeasuredHeight() | 980 val newwidth = item.getMeasuredWidth() |
981 } | 981 |
982 // Handle non-expandable items | 982 if(newwidth > 0) { |
983 if(hsize == 0 && w > 0) { | 983 weight = newwidth.toFloat() |
984 params.width = w | 984 } |
985 } | 985 } |
986 if(vsize == 0 && h > 0) { | 986 } |
987 params.height = h | 987 if(vsize == 0) { |
988 } | 988 if (height > 0) { |
989 } | 989 h = height |
990 } | |
991 } else { | |
992 if (height > 0) { | |
993 weight = height.toFloat() | |
994 } else if (height == -1) { | |
995 val newheight = item.getMeasuredHeight() | |
996 | |
997 if(newheight > 0) { | |
998 weight = newheight.toFloat() | |
999 } | |
1000 } | |
1001 } | |
1002 } | |
1003 | |
1004 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h) | |
990 | 1005 |
991 // Handle expandable items by giving them a weight... | 1006 // Handle expandable items by giving them a weight... |
992 // in the direction of the box. | 1007 // in the direction of the box. |
993 if (box.orientation == LinearLayout.VERTICAL) { | 1008 if (box.orientation == LinearLayout.VERTICAL) { |
994 if (vsize != 0) { | 1009 if (vsize != 0) { |
995 if (w > 0) { | 1010 params.weight = weight |
996 params.weight = w.toFloat() | |
997 } else { | |
998 params.weight = 1F | |
999 } | |
1000 } | 1011 } |
1001 } else { | 1012 } else { |
1002 if (hsize != 0) { | 1013 if (hsize != 0) { |
1003 if (h > 0) { | 1014 params.weight = weight |
1004 params.weight = h.toFloat() | |
1005 } else { | |
1006 params.weight = 1F | |
1007 } | |
1008 } | 1015 } |
1009 } | 1016 } |
1010 // Gravity needs to match the expandable settings | 1017 // Gravity needs to match the expandable settings |
1011 var grav: Int = Gravity.CLIP_HORIZONTAL or Gravity.CLIP_VERTICAL | 1018 var grav: Int = Gravity.CLIP_HORIZONTAL or Gravity.CLIP_VERTICAL |
1012 if (hsize != 0 && vsize != 0) { | 1019 if (hsize != 0 && vsize != 0) { |