Android Question Hover over a view

Alexander Stolte

Expert
Licensed User
Longtime User
Hello,

My question is, how is possible to click a buton if i hover over there, for example:

My finger starts from the activity and get to a picture, if i hover over this picture, then is the picture bigger.

EDIT: like facebook emojis
Greetings
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Use the touch event for that
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Globals
    
    Dim imgpanel As Panel
    Dim bmp As BitmapDrawable
End Sub

Sub Activity_Create(FirstTime As Boolean)
  
   
    bmp.Initialize(LoadBitmap(File.DirAssets,"icon.png"))
   
    imgpanel.Initialize("imgpanel")
    Activity.AddView(imgpanel,50%x,50%y,200dip,200dip)
    imgpanel.SetLayout(50%x - imgpanel.Width/2,50%y - imgpanel.Height/2,200dip,200dip)
    imgpanel.Background = bmp
   
End Sub

Sub imgpanel_Touch (Action As Int, X As Float, Y As Float)
    Select Action
        Case Activity.ACTION_DOWN
            imgpanel.Setlayout(imgpanel.Top,imgpanel.Width,imgpanel.Width*1.5,imgpanel.Height*1.5)
            imgpanel.Setlayout(50%x - imgpanel.Width/2,50%y - imgpanel.height/2,imgpanel.Width,imgpanel.Height)
        Case Activity.ACTION_UP
            imgpanel.RemoveView
            Activity.AddView(imgpanel,50%x,50%y,200dip,200dip)
            imgpanel.SetLayout(50%x - imgpanel.Width/2,50%y - imgpanel.Height/2,200dip,200dip)
            imgpanel.Background = bmp
    End Select
   
End Sub
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
The Problem is, the touch event is not triggered, if my fingers comes from the Activity.

Another example for better understand:

Facebook app: if you press the like button, comes the emojis visible, since where the finger is, this emoji is bigger.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
The Problem is, the touch event is not triggered, if my fingers comes from the Activity.

Activity also has a touch event.
So i would advice you to store all views x,y,w,h with a custom type and trigger only the activity touch event and if x/y from touch on activity is inside a view do what ever you want.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
here is an example in b4j but it should not be to hard to convert it to b4a.
(i hope this is what you meant above)
 

Attachments

  • b4jEx1.jar
    342.3 KB · Views: 226
  • b4jEx1.zip
    4.5 KB · Views: 234
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
using full screen panel
B4X:
Sub Globals

    Dim imgpanel As Panel
    Dim bmp As BitmapDrawable
    Dim imgv As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)

  
    bmp.Initialize(LoadBitmap(File.DirAssets,"icon.png"))
    imgv.Initialize("")
    imgpanel.Initialize("imgpanel")
    imgpanel.Color = Colors.Blue
    Activity.AddView(imgpanel,0,0,100%x,100%y)
  
    imgpanel.AddView(imgv,0,0,200dip,200dip)
    imgv.setlayout(50%x - imgv.Width/2,50%y - imgv.Height/2,imgv.Width,imgv.Height)
  
    imgv.Background = bmp
  
End Sub

Sub imgpanel_Touch (Action As Int, X As Float, Y As Float)
    Select Action
        Case Activity.ACTION_DOWN
            If X>imgv.Left And X< imgv.Left + imgv.Width And Y> imgv.Top And Y< imgv.Top + imgv.Height Then
            imgv.Setlayout(0,0,imgv.Width*1.5,imgv.Height*1.5)
            imgv.Setlayout(50%x - imgv.Width/2,50%y - imgv.height/2,imgv.Width,imgv.Height)
            imgv.Enabled = False
            End If
          
        Case Activity.ACTION_UP
            imgv.RemoveView
            imgpanel.AddView(imgv,50%x,50%y,200dip,200dip)
            imgv.SetLayout(50%x - imgv.Width/2,50%y - imgv.Height/2,200dip,200dip)
            imgv.Background = bmp
            imgv.Enabled = True
          
        Case Activity.ACTION_MOVE
            If X>imgv.Left And X< imgv.Left + imgv.Width And Y> imgv.Top And Y< imgv.Top + imgv.Height Then
                If imgv.Enabled = False Then
                  
                Else
              
                imgv.Enabled = False
                imgv.Setlayout(0,0,imgv.Width*1.5,imgv.Height*1.5)
                imgv.Setlayout(50%x - imgv.Width/2,50%y - imgv.height/2,imgv.Width,imgv.Height)
              
              
            End If
          
            Else
              
                    imgv.RemoveView
                    imgpanel.AddView(imgv,50%x,50%y,200dip,200dip)
                    imgv.SetLayout(50%x - imgv.Width/2,50%y - imgv.Height/2,200dip,200dip)
                    imgv.Background = bmp
                    imgv.Enabled = True
          
          
            End If
            
    End Select
  
End Sub
 
Upvote 0
Top