# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1619174457 0 # Node ID b0230e378667bc8fb48fd478fa010dbeccf75cf1 # Parent 3fbf8783122d3db1c5f2681de564fbde58a0f31f Android: Improvements to boxPack to handle more parameters... However the layout is still not perfect, hopefully we can get LinearLayout... to work well enough to simulate the boxes on other platforms. diff -r 3fbf8783122d -r b0230e378667 android/DWindows.kt --- a/android/DWindows.kt Thu Apr 22 17:49:20 2021 +0000 +++ b/android/DWindows.kt Fri Apr 23 10:40:57 2021 +0000 @@ -2,6 +2,8 @@ import android.os.Bundle import android.text.method.PasswordTransformationMethod +import android.util.Half.toFloat +import android.view.Gravity import android.view.View import android.widget.* import androidx.appcompat.app.AppCompatActivity @@ -50,20 +52,58 @@ fun boxPack(box: LinearLayout, item: View, index: Int, width: Int, height: Int, hsize: Int, vsize: Int, pad: Int) { - var w: Int = width; - var h: Int = height; + var w: Int = LinearLayout.LayoutParams.WRAP_CONTENT + var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT + + if(item is LinearLayout) { + if (vsize > 0) { + h = LinearLayout.LayoutParams.MATCH_PARENT + } + if (hsize > 0) { + w = LinearLayout.LayoutParams.MATCH_PARENT + } + } + var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h) - if(hsize > 0) { - w = LinearLayout.LayoutParams.MATCH_PARENT - } else if(w < 1) { - w = LinearLayout.LayoutParams.WRAP_CONTENT + if(item !is LinearLayout && (width != -1 || height != -1)) { + item.measure(0,0) + if (width > 0) { + w = width + } else if(width == -1) { + w = item.getMeasuredWidth() + } + if (height > 0) { + h = height + } else if(height == -1) { + h = item.getMeasuredHeight() + } } if(vsize > 0) { - h = LinearLayout.LayoutParams.MATCH_PARENT - } else if(h < 1) { - h = LinearLayout.LayoutParams.WRAP_CONTENT + if(w > 0) { + params.weight = w.toFloat() + } else { + params.weight = 1F + } + } + if(hsize > 0) { + if(h > 0) { + params.weight = h.toFloat() + } else { + params.weight = 1F + } } - item.layoutParams = LinearLayout.LayoutParams(w, h) + if(pad > 0) { + params.setMargins(pad, pad, pad, pad) + } + var grav: Int = Gravity.CLIP_HORIZONTAL or Gravity.CLIP_VERTICAL + if(hsize > 0 && vsize > 0) { + params.gravity = Gravity.FILL or grav + } else if(hsize > 0) { + params.gravity = Gravity.FILL_HORIZONTAL or grav + } else if(vsize > 0) { + params.gravity = Gravity.FILL_VERTICAL or grav + } + item.layoutParams = params box.addView(item) }