Cursussen/Courses Codesnippets     Top 
B4A-chess - Screen adjustments


Screen adjustments
Add the following declarations in the Class_Globals subroutine:
	Private screensize As Double = GetDeviceLayoutValues.ApproximateScreenSize
	Private devwidth As Int
	Private devheight As Int
	Private cellwidth As Int
	Private cellheight As Int
Add the following code to the B4XPage_Created subroutine:
	Dim screensize As Double = GetDeviceLayoutValues.ApproximateScreenSize
	Dim devwidth As Int = GetDeviceLayoutValues.Width/2
	Dim devheight As Int = (GetDeviceLayoutValues.height/2) - 40dip
	If screensize > 8 Then
		Dim devwidth As Int = GetDeviceLayoutValues.Width
		Dim devheight As Int = GetDeviceLayoutValues.height - 80dip
		cellwidth = DipToCurrent(devwidth/9)
		cellheight = DipToCurrent(devheight/11.5)
	Else
		cellwidth = DipToCurrent(devwidth/9)
		cellheight = DipToCurrent(devheight/13.5)
	End If
	Log("devwidth: " & devwidth)
	Log("devheight: " & devheight)
	Log("cellwidth: " & cellwidth)
	Log("cellheight: " & cellheight)
If the dividers (9, 11.5 and 13.5) are not good for your device you can change them.
These adjustments were tested on a Samsung Galaxy Tab E tablet with a 9.6 inch screen.
And now we go over the code and change some lines.
Before deleting the old lines you might want to put them in comments!
In B4XPage_Created:
	DestRect.Initialize(5dip, 5dip, cellwidth - 5dip, cellheight - 5dip)
	BorderRect.Initialize(0dip,0dip,cellwidth,cellheight)
setup_board:
			pnlmain.AddView(pnl,30dip+(c*cellwidth),30dip+(r*cellheight),cellwidth,cellheight)
set_sides above cnv.drawtext in the inner loop:
If screensize > 8 Then
	cnv.DrawText(strlet,10dip+(c*cellwidth)-20dip,10dip+(8.5*cellheight),tfont,20,Colors.Gray,"LEFT")					
Else
	cnv.DrawText(strlet,10dip+(c*cellwidth)-5dip,10dip+(9*cellheight),tfont,20,Colors.Gray,"LEFT")
End If
refresh_board:
			pnlmain.AddView(pnl,30dip+(c*cellwidth),30dip+(r*cellheight),cellwidth,cellheight)
show_studyboard:
			pnlmain.AddView(pnl,30dip+(c*cellwidth),30dip+(r*cellheight),cellwidth,cellheight)
show_savedialog below the first line with the CreatePanel function:
	If screensize > 8 Then
		pnl.SetLayoutAnimated(0, 0, 0, (devwidth - 100dip), ((devheight/2) -200dip))		
	Else
		pnl.SetLayoutAnimated(0, 0, 0, 300dip, 200dip)			
	End If


X

Paragraphs

Screen adjustments