Android Question Image Overlay - Two layouts or panels?

jmoeller

Member
Licensed User
Longtime User
I am writing a very basic "picture frame" application. It will display random photos from my collection. I would like to touch the photo and have various transparent icons display such as Back, Settings, Info. I am not sure of the best way to achieve this and would appreciate input. Currently, I have a layout with the full screen photo as an ImageView. I have a second layout that has the transparent icons. When you touch the photo, the overlay appears (Activity.LoadLayout("Overlay") but I can't interact with it. I've read that panels might be the way to go. I enjoy learning, so I don't need code but I could use advice as to the best way to achieve this functionality.
 

eurojam

Well-Known Member
Licensed User
Longtime User
Here is a small example, adding a panel and a button to the activity. If you click the imageview, the panel will be visible
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
   Private iv As ImageView
   Private p As Panel
   Private pState As Int = 0 'panel visible or not
   Private bt 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("Layout1")
   iv.Initialize("iv")
   Activity.AddView(iv,0,0,100%x,100%y)
   Dim b As Bitmap
   b.Initialize(File.DirAssets,"1.png")
   iv.Bitmap=b

   p.Initialize("panel")
   Activity.AddView(p,-100dip, 0, 100dip,100dip)
   Dim cd As ColorDrawable
   cd.Initialize(Colors.ARGB(100, 255,0,0), 0)
   p.Background = cd
   bt.Initialize("Button")
   p.AddView(bt, 20dip,20dip, 60dip,60dip)
End Sub

Sub iv_Click
    If pState = 0 Then
      p.SetLayoutAnimated(100, 0,0 , 100dip,100dip)
      pState = 1
    Else
      p.SetLayoutAnimated(100, -100dip,0 , 100dip,100dip)
      pState = 0     
    End If
End Sub

Sub button_click
    Log("Button click")
End Sub
 

Attachments

  • test.zip
    13.8 KB · Views: 189
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…