Sub Process_Globals
Private MainForm As Form
Private ImageView1 As ImageView
Private xui As XUI
Private ImageView2 As ImageView
Private ImageView3 As ImageView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
MainForm.Show
CreateComicBalloon(ImageView1)
CreateComicBalloon(ImageView2)
CreateComicBalloon(ImageView3)
End Sub
Sub CreateComicBalloon (ImageView As B4XView)
Dim bcGradient As BitmapCreator
bcGradient.Initialize(ImageView.Width / xui.Scale, ImageView.Height / xui.Scale)
bcGradient.FillGradient(Array As Int(xui.Color_White, 0xFFCACACA), bcGradient.TargetRect, "TOP_BOTTOM")
Dim bc As BitmapCreator
bc.Initialize(bcGradient.mWidth, bcGradient.mHeight)
Dim brush As BCBrush = bc.CreateBrushFromBitmapCreator(bcGradient)
Dim borderBrush As BCBrush = bc.CreateBrushFromColor(xui.Color_Black)
Dim r As B4XRect
r.Initialize(0, 0, bc.mWidth, bc.mHeight * 0.8)
bc.DrawRectRounded2(r, brush, True, 0, 50)
bc.DrawRectRounded2(r, borderBrush, False, 2, 50)
Dim path As BCPath
Dim len As Int = (bc.mHeight - r.Bottom) / 3
path.Initialize(60, r.Bottom-2)
path.LineTo(60 + len, bc.mHeight)
path.LineTo(60 + 2 * len, r.Bottom-2)
bc.DrawPath2(path, brush, True, 0)
path.RemoveLastPoint
bc.DrawPath2(path, borderBrush, False, 1)
bc.SetBitmapToImageView(bc.Bitmap, ImageView)
End Sub
I have to know whether I'm badly managing the 9patches or if I draw them wrong (but also the ones I found - it's not important that they are balloons - they don't give the expected results) or what else.
[However, there is a small bug in your routine, Erel (and if anyone wanted to use it...)]
View attachment 81275
(Post #1)It works 100%, your doing it incorrectly.
(Post #8)Where am I wrong?
maybe I don't know how to use it
and I don't understand why but it's ok.Welcome to my ignore list, done...
Sub AdjustLabelHeight(Lbl As Label, Text As String ,TextSize As Float)
Private jolbl As JavaObject
Private pl, pt, pr, pb As Int
jolbl = Lbl
pl = jolbl.RunMethod("getPaddingLeft", Null)
pt = jolbl.RunMethod("getPaddingTop", Null)
pr = jolbl.RunMethod("getPaddingRight", Null)
pb = jolbl.RunMethod("getPaddingBottom", Null)
Private lblDummy As Label
lblDummy.Initialize("")
Activity.AddView(lblDummy, 0, 0, Lbl.Width - pl - pr, Lbl.Height - pt - pb)
lblDummy.Text = Text
lblDummy.TextSize = TextSize
Lbl.Text = Text
Lbl.TextSize = TextSize
Dim su As StringUtils
Lbl.Height = su.MeasureMultilineTextHeight(lblDummy, Text) + pt + pb
lblDummy.RemoveView
End Sub
Sub AdjustLabelHeight(Lbl As Label, Text As String ,TextSize As Float)
Private pd(4) As Int
pd = Lbl.Padding
Private lblDummy As Label
lblDummy.Initialize("")
Activity.AddView(lblDummy, 0, 0, Lbl.Width - pd(0) - pd(2), Lbl.Height - pd(1) - pd(3))
lblDummy.Text = Text
lblDummy.TextSize = TextSize
Lbl.Text = Text
Lbl.TextSize = TextSize
Dim su As StringUtils
Lbl.Height = su.MeasureMultilineTextHeight(lblDummy, Text) + pd(1) + pd(3)
lblDummy.RemoveView
End Sub
I had thought to Padding but I knew (or thought I knew) that it was fixed for each type of View and that it didn't depend on the content.The problem is the Padding!
I agree with this statement.First of all, thank you Klaus for having tried and solved the problem (you're always willing to help, great Klaus).
I don't agree. Other members have tried to help you. I created a full example based on a different approach just to help you solve your problem. Even if it was not useful for you it doesn't mean that I haven't invested quite a lot of time in writing this code (post #3).I renew my thanks to you, Klaus, for having tried, for having solved, for explaining and also for having taken seriously my request while others ignored it
I renew my thanks to you, Klaus, for having tried, for having solved, for explaining and also for having taken seriously my request while others ignored it
I know that you, Erel, have spent time developing that useful routine that I appreciate and also I want to study it (I want to study everything about CreateBitmap) and thank you again but what I wanted to understand was if I had a wrong idea about how 9patches work or if I used them badly. The only member who downloaded one of the two projects I attached was Klaus.I don't agree. Other members have tried to help you. I created a full example based on a different approach just to help you solve your problem. Even if it was not useful for you it doesn't mean that I haven't invested quite a lot of time in writing this code (post #3).
If I were to implement such solution I would have chosen the drawing approach as it is more flexible. Adding the text should be simple.
' Returns the number of text lines.
Sub AdjustLabelHeight(Lbl As Label) As Int
Dim lblDummy As Label
lblDummy.Initialize("")
Dim Parent As Panel = Lbl.Parent
Parent.AddView(lblDummy, 0, 0, Lbl.Width - Lbl.Padding(0) - Lbl.Padding(2), Lbl.Height - Lbl.Padding(1) - Lbl.Padding(3))
lblDummy.Text = Lbl.Text
lblDummy.TextSize = Lbl.TextSize
lblDummy.Typeface = Lbl.Typeface
Dim su As StringUtils
Lbl.Height = su.MeasureMultilineTextHeight(lblDummy, Lbl.Text) + Lbl.Padding(1) + Lbl.Padding(3)
lblDummy.RemoveView
Dim Source As JavaObject = Lbl
Dim LineCount As Int = Source.RunMethod("getLineCount", Null) + 1
Return LineCount
End Sub