Mercurial > dwindows
changeset 2478:b0230e378667
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.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 23 Apr 2021 10:40:57 +0000 |
parents | 3fbf8783122d |
children | 54b0008a0569 |
files | android/DWindows.kt |
diffstat | 1 files changed, 50 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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) }