Text Shift in a 9 Patched Button

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I'm using a Statelist and a couple 9 Patch images for a button to show pressed. Works fine drawing it popped up and down, but the text just ruins the 3D effect. On the Pressed version I shift the content area down and to the right, but the text doesn't shift on pressing. I figured it might be Gravity since it draws centered, so I tried setting it to no gravity with no change. Other gravity settings seem to override the 9 Patch Content area too, so I can't really shift gravity on up/down events or it will draw wrong.

Is there no way of shifting the the text using the statelist and/or 9 Patch?
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Label works pretty slick and shifts the text! :sign0060:

I used Reflection to get a touch event so I can process the animation a little better. I added code so on action up or going outside the bounds of the control the button is drawn with buttonup 9 Patch. Works great on getting action up and going outside the bounds on the X axis, but the Y axis seems to have an accuracy problem on one of my devices and doesn't detect it going out of bounds (Appears to stop getting events with a Y of about 50-70). Most likely a screen/hardware thing, but found it interesting.

B4X:
Sub Button_Touch(viewTag As Object, action As Int, x As Float, y As Float, moveEvent As Object) As Boolean
Dim myControl As Label
Dim a As Activity

   myControl = Sender
   If action = 0 Then myControl.Background = SetNinePatchDrawable("buttondown")
   If action = 1 OR x < 0 OR y < 0 OR x > myControl.Width OR y > myControl.Height Then myControl.Background = SetNinePatchDrawable("buttonup")
End Sub
 
Upvote 0
Top