diff --git a/app/src/main/java/org/linphone/activities/voip/views/GridBoxLayout.kt b/app/src/main/java/org/linphone/activities/voip/views/GridBoxLayout.kt
new file mode 100644
index 000000000..b474739fd
--- /dev/null
+++ b/app/src/main/java/org/linphone/activities/voip/views/GridBoxLayout.kt
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2010-2020 Belledonne Communications SARL.
+ *
+ * This file is part of linphone-android
+ * (see https://www.linphone.org).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.linphone.activities.voip.views
+import android.annotation.SuppressLint
+import android.content.Context
+import android.util.AttributeSet
+import android.widget.GridLayout
+import androidx.core.view.children
+import org.linphone.core.tools.Log
+
+class GridBoxLayout : GridLayout {
+
+ companion object {
+ private val placementMatrix = arrayOf(intArrayOf(1, 2, 3, 4, 5, 6), intArrayOf(1, 1, 2, 2, 3, 3), intArrayOf(1, 1, 1, 2, 2, 2), intArrayOf(1, 1, 1, 1, 2, 2), intArrayOf(1, 1, 1, 1, 1, 2), intArrayOf(1, 1, 1, 1, 1, 1))
+ }
+
+ constructor(context: Context) : this(context, null)
+ constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
+ constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
+ context,
+ attrs,
+ defStyleAttr
+ )
+
+ var centerContent: Boolean = false
+
+ @SuppressLint("DrawAllocation")
+ override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
+ val availableSize = Pair(right - left, bottom - top)
+ if (childCount == 0)
+ return
+ children.forEach { it.layoutParams = LayoutParams() }
+ var cellSize = 0
+ for (index in 1..childCount) {
+ val neededColumns = placementMatrix[index - 1][childCount - 1]
+ val candidateWidth = 1 * availableSize.first / neededColumns
+ val candidateHeight = 1 * availableSize.second / index
+ val candidateSize = if (candidateWidth < candidateHeight) candidateWidth else candidateHeight
+ if (candidateSize > cellSize) {
+ columnCount = neededColumns
+ rowCount = index
+ cellSize = candidateSize
+ }
+ }
+ super.onLayout(true, left, top, right, bottom) // Required in this position
+ children.forEach { child ->
+ child.layoutParams.width = cellSize
+ child.layoutParams.height = cellSize
+ child.requestLayout()
+ }
+ if (centerContent) {
+ setPadding((availableSize.first - (columnCount * cellSize)) / 2, (availableSize.second - (rowCount * cellSize)) / 2, (availableSize.first - (columnCount * cellSize)) / 2, (availableSize.second - (rowCount * cellSize)) / 2)
+ }
+ Log.d("[GridBoxLayout] cellsize=$cellSize columns=$columnCount rows=$rowCount availablesize=$availableSize")
+ }
+}
diff --git a/app/src/main/res/layout-land/voip_conference_grid.xml b/app/src/main/res/layout-land/voip_conference_grid.xml
index 15c4f3721..bad39308f 100644
--- a/app/src/main/res/layout-land/voip_conference_grid.xml
+++ b/app/src/main/res/layout-land/voip_conference_grid.xml
@@ -106,19 +106,15 @@
-
+ centerContent="@{true}"
+ />
diff --git a/app/src/main/res/layout/voip_conference_grid.xml b/app/src/main/res/layout/voip_conference_grid.xml
index 202306715..bad39308f 100644
--- a/app/src/main/res/layout/voip_conference_grid.xml
+++ b/app/src/main/res/layout/voip_conference_grid.xml
@@ -106,19 +106,15 @@
-
+ centerContent="@{true}"
+ />
diff --git a/app/src/main/res/layout/voip_conference_participant_remote_grid.xml b/app/src/main/res/layout/voip_conference_participant_remote_grid.xml
index 0f9a60019..afe46d9a6 100644
--- a/app/src/main/res/layout/voip_conference_participant_remote_grid.xml
+++ b/app/src/main/res/layout/voip_conference_participant_remote_grid.xml
@@ -10,19 +10,18 @@
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:padding="5dp">