Mercurial > dwindows
comparison android/DWindows.kt @ 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 |
comparison
equal
deleted
inserted
replaced
2477:3fbf8783122d | 2478:b0230e378667 |
---|---|
1 package org.dbsoft.dwindows.dwtest | 1 package org.dbsoft.dwindows.dwtest |
2 | 2 |
3 import android.os.Bundle | 3 import android.os.Bundle |
4 import android.text.method.PasswordTransformationMethod | 4 import android.text.method.PasswordTransformationMethod |
5 import android.util.Half.toFloat | |
6 import android.view.Gravity | |
5 import android.view.View | 7 import android.view.View |
6 import android.widget.* | 8 import android.widget.* |
7 import androidx.appcompat.app.AppCompatActivity | 9 import androidx.appcompat.app.AppCompatActivity |
8 | 10 |
9 | 11 |
48 return box | 50 return box |
49 } | 51 } |
50 | 52 |
51 fun boxPack(box: LinearLayout, item: View, index: Int, width: Int, height: Int, hsize: Int, vsize: Int, pad: Int) | 53 fun boxPack(box: LinearLayout, item: View, index: Int, width: Int, height: Int, hsize: Int, vsize: Int, pad: Int) |
52 { | 54 { |
53 var w: Int = width; | 55 var w: Int = LinearLayout.LayoutParams.WRAP_CONTENT |
54 var h: Int = height; | 56 var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT |
55 | 57 |
56 if(hsize > 0) { | 58 if(item is LinearLayout) { |
57 w = LinearLayout.LayoutParams.MATCH_PARENT | 59 if (vsize > 0) { |
58 } else if(w < 1) { | 60 h = LinearLayout.LayoutParams.MATCH_PARENT |
59 w = LinearLayout.LayoutParams.WRAP_CONTENT | 61 } |
62 if (hsize > 0) { | |
63 w = LinearLayout.LayoutParams.MATCH_PARENT | |
64 } | |
65 } | |
66 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h) | |
67 | |
68 if(item !is LinearLayout && (width != -1 || height != -1)) { | |
69 item.measure(0,0) | |
70 if (width > 0) { | |
71 w = width | |
72 } else if(width == -1) { | |
73 w = item.getMeasuredWidth() | |
74 } | |
75 if (height > 0) { | |
76 h = height | |
77 } else if(height == -1) { | |
78 h = item.getMeasuredHeight() | |
79 } | |
60 } | 80 } |
61 if(vsize > 0) { | 81 if(vsize > 0) { |
62 h = LinearLayout.LayoutParams.MATCH_PARENT | 82 if(w > 0) { |
63 } else if(h < 1) { | 83 params.weight = w.toFloat() |
64 h = LinearLayout.LayoutParams.WRAP_CONTENT | 84 } else { |
85 params.weight = 1F | |
86 } | |
65 } | 87 } |
66 item.layoutParams = LinearLayout.LayoutParams(w, h) | 88 if(hsize > 0) { |
89 if(h > 0) { | |
90 params.weight = h.toFloat() | |
91 } else { | |
92 params.weight = 1F | |
93 } | |
94 } | |
95 if(pad > 0) { | |
96 params.setMargins(pad, pad, pad, pad) | |
97 } | |
98 var grav: Int = Gravity.CLIP_HORIZONTAL or Gravity.CLIP_VERTICAL | |
99 if(hsize > 0 && vsize > 0) { | |
100 params.gravity = Gravity.FILL or grav | |
101 } else if(hsize > 0) { | |
102 params.gravity = Gravity.FILL_HORIZONTAL or grav | |
103 } else if(vsize > 0) { | |
104 params.gravity = Gravity.FILL_VERTICAL or grav | |
105 } | |
106 item.layoutParams = params | |
67 box.addView(item) | 107 box.addView(item) |
68 } | 108 } |
69 | 109 |
70 fun boxUnpack(item: View) | 110 fun boxUnpack(item: View) |
71 { | 111 { |