changeset 2675:a7868380098f

Android: LinearLayout does not allow null views, if null, create a Placeholder view. Pack the empty placeholder into the LinearLayout to accomplish the same effect. This allows us to center things with expandable placeholders.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 19 Oct 2021 11:01:16 +0000
parents dd0b29320a3d
children a43cf048ff17
files android/DWindows.kt android/dw.cpp
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Mon Oct 18 20:50:55 2021 +0000
+++ b/android/DWindows.kt	Tue Oct 19 11:01:16 2021 +0000
@@ -44,6 +44,7 @@
 import androidx.collection.SimpleArrayMap
 import androidx.constraintlayout.widget.ConstraintLayout
 import androidx.constraintlayout.widget.ConstraintSet
+import androidx.constraintlayout.widget.Placeholder
 import androidx.core.app.NotificationCompat
 import androidx.core.app.NotificationManagerCompat
 import androidx.core.content.res.ResourcesCompat
@@ -1582,7 +1583,7 @@
 
     fun boxPack(
         boxview: View,
-        item: View,
+        packitem: View?,
         index: Int,
         width: Int,
         height: Int,
@@ -1594,6 +1595,13 @@
             var w: Int = LinearLayout.LayoutParams.WRAP_CONTENT
             var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT
             var box: LinearLayout? = null
+            var item: View? = packitem
+
+            // We can't pack nothing, so create an empty placeholder to pack
+            if(item == null) {
+                item = Placeholder(this)
+                item.emptyVisibility = View.VISIBLE
+            }
 
             // Handle scrollboxes by pulling the LinearLayout
             // out of the ScrollView to pack into
--- a/android/dw.cpp	Mon Oct 18 20:50:55 2021 +0000
+++ b/android/dw.cpp	Tue Oct 19 11:01:16 2021 +0000
@@ -1431,7 +1431,7 @@
 {
     JNIEnv *env;
 
-    if(box && item && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
+    if(box && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
     {
         // First get the class that contains the method you need to call
         jclass clazz = _dw_find_class(env, DW_CLASS_NAME);