Android Question Set position of an aray of imageviews (x,y)

LéonE

Member
Licensed User
Longtime User
Hi,

New to B4A and have a problem with variable imageview.
i want to line-up the images with something like this.
the dim ImV1(40) as imageview is done above


Posleft =
10

PosTop =
10

For t= 1 To 40

ImV1(t).Width = 70dip
ImV1(t).Height = 70dip
ImV1(t).Bitmap= LoadBitmap(File.DirAssets, "MyPicture.jpg")

If t<11Then 'until 11 is one line

ImV1(t).Left= PosLeft

ImV1(t).Top = PosTop

PosLeft=PosLeft + 80 '10dip between the imageviews

Else

PosLeft =
10 'left is resetted

PosTop =
80 ' top as for line.

EndIf
ImV1(t).Visible=True

Next


any suggestions why this is not working?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Use code-tag when posting code.

WHAT is NOT working? Which errors you get?

BTW: Use dip.

wrong
B4X:
Posleft = 10
PosTop = 10

right
B4X:
Posleft = 10dip
PosTop = 10dip
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Can you use the [ code ] tags to make the code more readable please?

What are you expecting to happen?

What is happening?
 
Upvote 0

LéonE

Member
Licensed User
Longtime User
B4X:
Dim PosLeft As Int
Dim PosTop As Int
Posleft = 10dip
PosTop = 10dip
For t= 1 To 40
    ImV1(t).Bitmap = LoadBitmap(File.DirAssets, "brain.jpg")
If t<11 Then    'until 11 is one line
    ImV1(t).Width  = 70dip
    ImV1(t).Height = 70dip
    ImV1(t).Left= PosLeft
    ImV1(t).Top = PosTop
    PosTop=PosTop + 80    '10dip between the imageviews
Else
      PosLeft = 10
      PosTop = 80
End If  
    ImV1(t).Visible=True
Next
Have you compiled in debug mode? Does the unfiltered log show any error?

i did compile and run. also there is no error message.
 
Upvote 0

LéonE

Member
Licensed User
Longtime User
it seems to be an inizialize problem.
seen with debug (legasy).
how to do this now in my case:

ImV1
(t).Initialize ("")...?
 
Upvote 0

LéonE

Member
Licensed User
Longtime User
Where is the code that creates the image views and adds them to the activity or panel?
I added folowing line in de For t=1to40:


activity.AddView(ImV1(t),10dip,10dip,70dip,70dip)

but keep getting error now on the initialize
what to write in there? i tried ImV1(t).Initialize ("ImageView1")


Thanks.
 
Upvote 0

LéonE

Member
Licensed User
Longtime User
Two suggestions:
- Read this thread How to ask a question
- Send your project as a zip file (IDE menu Files / Export As Zip)
So we can see what you have done and how.

The quastion can be closed. i figured is out with the remark of Erel.
I did not initialise and no add.
the thing i have to figure out now is the click event to all images shown.

Thanks
 
  • Like
Reactions: eps
Upvote 0

LéonE

Member
Licensed User
Longtime User
or pop it in a TableView or similar?
Thanks Eps. I have to go into that. as stated before i'm new in B4A and have still to figureout
how examples, without use of the designer, are working.
stil long way to go i gues...:(
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
the thing i have to figure out now is the click event to all images shown.

You set the eventname with the initialization... for ex iv.initialize("image")
B4X:
Sub image_Click
    If Sender Is Button
        Dim but As Button
        but = Sender
        Log(but.Text)
    End If
End Sub
 
Upvote 0
Top