Mercurial > dwindows
comparison android/DWindows.kt @ 2500:ac0b7e579229
Android: Implement dw_scrollbox_new() using ScrollView.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 05 May 2021 21:59:23 +0000 |
parents | ff3310fa6d72 |
children | 41984ffb5ca2 |
comparison
equal
deleted
inserted
replaced
2499:ff3310fa6d72 | 2500:ac0b7e579229 |
---|---|
201 } | 201 } |
202 box.setPadding(pad, pad, pad, pad) | 202 box.setPadding(pad, pad, pad, pad) |
203 return box | 203 return box |
204 } | 204 } |
205 | 205 |
206 fun scrollBoxNew(type: Int, pad: Int) : ScrollView { | |
207 val scrollBox = ScrollView(this) | |
208 val box = LinearLayout(this) | |
209 var dataArrayMap = SimpleArrayMap<String, Long>() | |
210 | |
211 scrollBox.tag = dataArrayMap | |
212 box.layoutParams = | |
213 LinearLayout.LayoutParams( | |
214 LinearLayout.LayoutParams.MATCH_PARENT, | |
215 LinearLayout.LayoutParams.MATCH_PARENT | |
216 ) | |
217 if (type > 0) { | |
218 box.orientation = LinearLayout.VERTICAL | |
219 } else { | |
220 box.orientation = LinearLayout.HORIZONTAL | |
221 } | |
222 box.setPadding(pad, pad, pad, pad) | |
223 // Add a pointer back to the ScrollView | |
224 box.tag = scrollBox | |
225 scrollBox.addView(box) | |
226 return scrollBox | |
227 } | |
228 | |
206 fun boxPack( | 229 fun boxPack( |
207 box: LinearLayout, | 230 boxview: View, |
208 item: View, | 231 item: View, |
209 index: Int, | 232 index: Int, |
210 width: Int, | 233 width: Int, |
211 height: Int, | 234 height: Int, |
212 hsize: Int, | 235 hsize: Int, |
213 vsize: Int, | 236 vsize: Int, |
214 pad: Int | 237 pad: Int |
215 ) { | 238 ) { |
216 var w: Int = LinearLayout.LayoutParams.WRAP_CONTENT | 239 var w: Int = LinearLayout.LayoutParams.WRAP_CONTENT |
217 var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT | 240 var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT |
218 | 241 var box: LinearLayout? = null |
219 if (item is LinearLayout) { | 242 |
243 // Handle scrollboxes by pulling the LinearLayout | |
244 // out of the ScrollView to pack into | |
245 if(boxview is LinearLayout) { | |
246 box = boxview as LinearLayout | |
247 } else if(boxview is ScrollView) { | |
248 var sv: ScrollView = boxview | |
249 | |
250 if(sv.getChildAt(0) is LinearLayout) { | |
251 box = sv.getChildAt(0) as LinearLayout | |
252 } | |
253 } | |
254 | |
255 if(box != null) { | |
256 if ((item is LinearLayout) or (item is ScrollView)) { | |
257 if (box.orientation == LinearLayout.VERTICAL) { | |
258 if (hsize > 0) { | |
259 w = LinearLayout.LayoutParams.MATCH_PARENT | |
260 } | |
261 } else { | |
262 if (vsize > 0) { | |
263 h = LinearLayout.LayoutParams.MATCH_PARENT | |
264 } | |
265 } | |
266 } | |
267 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h) | |
268 | |
269 if (item !is LinearLayout && (width != -1 || height != -1)) { | |
270 item.measure(0, 0) | |
271 if (width > 0) { | |
272 w = width | |
273 } else if (width == -1) { | |
274 w = item.getMeasuredWidth() | |
275 } | |
276 if (height > 0) { | |
277 h = height | |
278 } else if (height == -1) { | |
279 h = item.getMeasuredHeight() | |
280 } | |
281 } | |
220 if (box.orientation == LinearLayout.VERTICAL) { | 282 if (box.orientation == LinearLayout.VERTICAL) { |
221 if (hsize > 0) { | 283 if (vsize > 0) { |
222 w = LinearLayout.LayoutParams.MATCH_PARENT | 284 if (w > 0) { |
285 params.weight = w.toFloat() | |
286 } else { | |
287 params.weight = 1F | |
288 } | |
223 } | 289 } |
224 } else { | 290 } else { |
225 if (vsize > 0) { | 291 if (hsize > 0) { |
226 h = LinearLayout.LayoutParams.MATCH_PARENT | 292 if (h > 0) { |
293 params.weight = h.toFloat() | |
294 } else { | |
295 params.weight = 1F | |
296 } | |
227 } | 297 } |
228 } | 298 } |
229 } | 299 if (pad > 0) { |
230 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h) | 300 params.setMargins(pad, pad, pad, pad) |
231 | 301 } |
232 if (item !is LinearLayout && (width != -1 || height != -1)) { | 302 var grav: Int = Gravity.CLIP_HORIZONTAL or Gravity.CLIP_VERTICAL |
233 item.measure(0, 0) | 303 if (hsize > 0 && vsize > 0) { |
234 if (width > 0) { | 304 params.gravity = Gravity.FILL or grav |
235 w = width | 305 } else if (hsize > 0) { |
236 } else if (width == -1) { | 306 params.gravity = Gravity.FILL_HORIZONTAL or grav |
237 w = item.getMeasuredWidth() | 307 } else if (vsize > 0) { |
238 } | 308 params.gravity = Gravity.FILL_VERTICAL or grav |
239 if (height > 0) { | 309 } |
240 h = height | 310 item.layoutParams = params |
241 } else if (height == -1) { | 311 box.addView(item, index) |
242 h = item.getMeasuredHeight() | 312 } |
243 } | |
244 } | |
245 if (box.orientation == LinearLayout.VERTICAL) { | |
246 if (vsize > 0) { | |
247 if (w > 0) { | |
248 params.weight = w.toFloat() | |
249 } else { | |
250 params.weight = 1F | |
251 } | |
252 } | |
253 } else { | |
254 if (hsize > 0) { | |
255 if (h > 0) { | |
256 params.weight = h.toFloat() | |
257 } else { | |
258 params.weight = 1F | |
259 } | |
260 } | |
261 } | |
262 if (pad > 0) { | |
263 params.setMargins(pad, pad, pad, pad) | |
264 } | |
265 var grav: Int = Gravity.CLIP_HORIZONTAL or Gravity.CLIP_VERTICAL | |
266 if (hsize > 0 && vsize > 0) { | |
267 params.gravity = Gravity.FILL or grav | |
268 } else if (hsize > 0) { | |
269 params.gravity = Gravity.FILL_HORIZONTAL or grav | |
270 } else if (vsize > 0) { | |
271 params.gravity = Gravity.FILL_VERTICAL or grav | |
272 } | |
273 item.layoutParams = params | |
274 box.addView(item, index) | |
275 } | 313 } |
276 | 314 |
277 fun boxUnpack(item: View) { | 315 fun boxUnpack(item: View) { |
278 var box: LinearLayout = item.parent as LinearLayout | 316 var box: LinearLayout = item.parent as LinearLayout |
279 box.removeView(item) | 317 box.removeView(item) |