#Region Project Attributes
#ApplicationLabel: ImgView Centered
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private clvSchemes As CustomListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Main")
PrepareClv
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub PrepareClv
Dim i As Int : i=1
Dim cImageName As String
clvSchemes.Clear
For i=1 To 6
'Image File names. For Eg Picture1.png, Picture2.png, Picture3.png
cImageName="Picture" & i & ".png"
'Creating the Panel and other views to be placed on the Panel. Finally this Panel is added to the CustomListView
Dim oPanel As Panel
oPanel.Initialize("")
oPanel.Color = Colors.White
'The label used to display the Image Title
Dim oLblTitle As Label
oLblTitle.Initialize("")
oLblTitle.Text = cImageName
oLblTitle.Gravity = Gravity.CENTER_HORIZONTAL
oLblTitle.TextSize = 18
oLblTitle.TextColor = Colors.Gray
oLblTitle.Typeface = Typeface.DEFAULT_BOLD
' Create Bitmap
Dim oBitmap As Bitmap
oBitmap.Initialize(File.DirAssets, cImageName)
Dim oImgView As ImageView
oImgView.Initialize("")
oImgView.Bitmap = oBitmap
'oImgView.Gravity = Gravity.FILL
oPanel.AddView(oLblTitle ,0%x , 10dip, 100%x , 25dip )
oPanel.AddView(oImgView ,02%x , 30dip, 330dip, 200dip)
'Adjust ImageView based on the the Original Pictures aspect Ratio, so that the image is not stretched or disorted
AdjustImageView(oImgView, oBitmap, oPanel)
' Now Add Panel to the CustomListView
clvSchemes.Add(oPanel, 255dip, i )
Next
End Sub
Sub AdjustImageView(oImgView As ImageView, oBitmap As Bitmap, oPanel As Panel)
Dim Delta, Height, Width As Int
If oBitmap.Width / oBitmap.Height > oImgView.Width / oImgView.Height Then
Height = oBitmap.Height / oBitmap.Width * oImgView.Width
Delta = (oImgView.Height - Height) / 2
oImgView.Height = Height
oImgView.Top = oImgView.Top + Delta
Else
Width = oBitmap.Width / oBitmap.Height * oImgView.Height
Delta = (oImgView.Width - Width) / 2
oImgView.Width = Width
oImgView.Left = oImgView.Left + Delta
End If
'oImgView.Gravity = Gravity.FILL
oImgView.Gravity = Bit.Or(Gravity.FILL , Gravity.CENTER)
'oImgView.Left = ( oPanel.Width - Width)/2
'oImgView.Top = (oPanel.Height - Height)/2
oImgView.Bitmap = oBitmap
End Sub