victordiaz / PHONK

PHONK is a coding playground for new and old Android devices
https://phonk.app
GNU General Public License v3.0
463 stars 25 forks source link

`PLinearLayout.add` with weight doesn't work #140

Open notEvil opened 1 year ago

notEvil commented 1 year ago

This

function t(orientation, weight) {
  return ui.newView('text').text(orientation + ' ' + weight)
}

function l1(y, orientation, weight) {
  var linear_layout = ui.addLinearLayout(0, y, 1, 0.09)
  if (orientation != 'vertical') linear_layout.orientation(orientation)
  linear_layout.add(t(orientation, weight), 'name', weight)
}

l1(0.1, 'horizontal', 0)
l1(0.2, 'vertical', 0)
l1(0.3, 'horizontal', 1)
l1(0.4, 'vertical', 1)

function l2(y, orientation, weight) {
  var linear_layout = ui.addLinearLayout(0, y, 1, 0.09)
  if (orientation != 'vertical') linear_layout.orientation(orientation)
  linear_layout.addView(t(orientation, weight), new android.widget.LinearLayout.LayoutParams(-2, -2, weight))
}

l2(0.6, 'horizontal', 0)
l2(0.7, 'vertical', 0)
l2(0.8, 'horizontal', 1)
l2(0.9, 'vertical', 1)

creates a couple of linear layouts in two ways. The first using PLinearLayout.add and the second LinearLayout.addView with explicit LinearLayout.LayoutParams. Labels 1, 2 and 4 are not visible because their width is set to 0, see https://github.com/victordiaz/PHONK/blob/3c4024e447bdde2615403eaa3fc3e65005886590/PHONK-android/phonk_apprunner/src/main/java/io/phonk/runner/apprunner/api/widgets/PLinearLayout.java#L81