Android Question Inconsistent button placement with dips in a scrollview

DickD

Active Member
Licensed User
I am creating a layout in code which places radio buttons in a scrollview using dips as shown in the code below. In testing this on various android versions on various sized screens I get inconsistencies. On a 5" screen with Android 4.4.2 the buttons are spaced 3/4" apart, on a Android 6.0.1 with a 5.25" screen they are 3/8" apart and on an Android 4.2.2 tablet with a 10" screen they are 7/8" apart. Only the tablet seems to have the right placement: 120 dips = 7/8". Everything else, except for these buttons, is placed properly on all three screens using dips.

I thought dips solved this problem. How can I fix it?

B4X:
qScrollView.Initialize(1000dip)
Activity.AddView(qScrollView, 0dip, 40dip, 400dip,440dip)
qScrollView.Panel.Color = Colors.Blue
Activity.AddView(lblPanelTitle, 0dip, 5dip, 400dip,50dip)
dipCount=0

'Add the buttons
 
dipCount=0
For x = 1 To QuestionArray.ButtonsPerQuestion(layout)
dipCount=dipCount+120
qScrollView.Panel.AddView(qButton(x), 20dip, dipCount+0dip, 240dip, 50dip)
Next
 

DickD

Active Member
Licensed User
I suspect that the problem is here:
dipCount = dipCount + 120
Shouldn't it be:
dipCount = dipCount + 120dip
Ahhh..... that actually worked and I'm totally surprised since dipCount is just an integer variable. I wouldn't think you could add dips to an integer without causing a syntax/missmatch error. I don't see that explained anywhere in the documentation.

Thanks
 
Upvote 0
Top