Android Question where is the bug?

nocturn

New Member
Licensed User
Longtime User
I dont speak English, so using onlain-translator.
if something is not clear , ask

In my application, Panel add by Designer and ImageViews adds by code, depending on the value of variable ngame . The problem is: ImageViews is not visible. Panel's are visible. Where is the problem? here is the code:

B4X:
Sub inicio (ngame As Byte, orient As Boolean)
Dim x As Int
If orient=True Then
x=Activity.width
Else
x=Activity.height
End If
If x Mod ngame=0 Then
p1.width=x
Else
Do Until x Mod ngame=0
x=x-1
Loop
End If
p1.width=x
p1.height=p1.width
p1.top=0
p1.left=0
If orient=True Then
p2.width=p1.width
p2.height=Activity.height-p1.height
p2.left=0
p2.top=p1.height
Else If orient=False Then
p2.height=p1.height
p2.width=Activity.width-p1.width
p2.top=0
p2.left=p1.width
End If
'hier I start add imageviews by code

Dim i As Byte
Dim leftx, topy, widthx,heighty As Int
leftx=0
topy=0
widthx=p1.Width/ngame
heighty=widthx
heighty=0

imag=Array As ImageView(im1,im2,im3,im4,im5,im6,im7,im8,im9,im10,im11,im12,im13,im14,im15,im16,im17,im18,im19,im20,im21,im22,im23,im24,im25)
For i=0 To ngame*ngame-1
imag(i).Initialize("im")
p1.AddView(imag(i),leftx ,topy ,widthx,heighty)

leftx=leftx+widthx
If ngame=3 AND  i=2 OR i=5 Then
leftx=0
topy=topy+widthx

End If





Next

End Sub
 

Attachments

  • example25.zip
    10.3 KB · Views: 176

imbault

Well-Known Member
Licensed User
Longtime User
Try first with buttons :

B4X:
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.
    Dim port As Boolean

    Private p1 As Panel
    Private p2 As Panel
    Dim im1,im2,im3,im4,im5,im6,im7,im8,im9,im10,im11,im12,im13,im14,im15,im16,im17,im18,im19,im20,im21,im22,im23,im24,im25 As Button
    Dim imag(24) As Button
 
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("maingame")
If Activity.Height>Activity.Width Then
port = True
Else
port=False
End If
inicio(Main.gamenumber,port)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub inicio (ngame As Byte, orient As Boolean)
Dim x As Int
If orient=True Then
x=Activity.width
Else
x=Activity.height
End If
If x Mod ngame=0 Then
p1.width=x
Else
Do Until x Mod ngame=0
x=x-1
Loop
End If
p1.width=x
p1.height=p1.width
p1.top=0
p1.left=0
If orient=True Then
p2.width=p1.width
p2.height=Activity.height-p1.height
p2.left=0
p2.top=p1.height
Else If orient=False Then
p2.height=p1.height
p2.width=Activity.width-p1.width
p2.top=0
p2.left=p1.width
End If
'hier I start add imageviews by code

Dim i As Byte
Dim leftx, topy, widthx,heighty As Int
leftx=0
topy=0
widthx=p1.Width/ngame
heighty=widthx
'heighty=0

imag=Array As Button(im1,im2,im3,im4,im5,im6,im7,im8,im9,im10,im11,im12,im13,im14,im15,im16,im17,im18,im19,im20,im21,im22,im23,im24,im25)
For i=0 To ngame*ngame-1

imag(i).Initialize("im")
p1.AddView(imag(i),leftx ,topy ,widthx,heighty)

leftx=leftx+widthx
If ngame=3 And  i=2 Or i=5 Then
leftx=0
topy=topy+widthx

End If

Next
End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
following @imbault 's suggestion (use buttons) and setting ngame to 2,3, or 4 give clear picture what's happening

also ... A little cleaner ..
B4X:
     p1.SetLayout(0, 0, x, p1.Width)
 
If orient Then     
    p2.SetLayout(0, p1.Height, p1.Width, Activity.Height - p1.Height)
Else
    p2.SetLayout(p1.Width, 0, Activity.Width - p1.Width, p1.Height)
End If
 
Last edited:
Upvote 0

imbault

Well-Known Member
Licensed User
Longtime User
Here is your project with buttons
... and try to indent a little bit
 

Attachments

  • example25but.zip
    7.2 KB · Views: 154
Upvote 0

nocturn

New Member
Licensed User
Longtime User
thank you very much, now it works,
but I do not understand why with images it not work?
sorry for my english-i use onlain-translate
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
but I do not understand why with images it not work?
If you loaded an image into the Image view .. or at least colored the ImageView you would have seen what was going on.
Without this the imageviews just blended into the panel.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…