Bug? Canvas measurestringwidth problem - Nikan99    Apr 28, 2023 So I create a background of every label as much as its text is. That works perfectly.
If beforebtnslength > Activity.Width Then
ycounter = ycounter + 1
beforebtnslength = 0
Else If beforebtnslength + SQLReader.GetString("name").Length*3%x > Activity.Width Then
ycounter = ycounter + 1 B4A Question [Solved by Klaus] 9Patch and MeasureStringWidth - klaus (first post)    Jun 20, 2019   (1 reaction) You should read the documentation for Canvas.
A Canvas is an object that draws on other views or (mutable) bitmaps.
When the canvas is initialized and set to draw on a view, a new mutable bitmap is created for that view background, the current view's background
is copied to the new bitmap and the ca B4A Question Long text length(single Line) fit label width automatically - klaus (first post)    Dec 05, 2022   (3 reactions) Initialize("") Label1.TextSize = 18 'Add the Label onot the HorizontalScrollView HorizontalScrollView1.Panel.AddView(Label1, 0, 0, 100dip, HorizontalScrollView1.Height) 'Remove the horizontal scrollbar Private jo = HorizontalScrollView1 As JavaObject jo.RunMethod("setHorizo B4A Question MeasureStringWidth: Cannot compile - Widget (first post)    Nov 21, 2016   (1 reaction) Sure. Your Canvas1 hasn't been initialized so it is still NULL.
Canvas1 would normally be the canvas of the view you are going to write to.
Canvas1.Initialize(Panel1)
width = Canvas1.MeasureStringWidth(t, Typeface.DEFAULT, 14)
or you can use a Bitmap
Private MyBitmap as Bitmap
MyBitmap.Initializ B4A Question MeasureStringWidth not working well - Cesaral    Mar 11, 2021 I am using an Android Canvas and the function MeasureStringWidth to measure the text drawn in the canvas by the DrawText function. I have tested it with several TT fonts and font sizes, with the same bad results.
The value given by MeasureStringWidth is a bit longer that the value of pixels of the B4A Question [Solved] StateListDrawable with B4XPages - klaus (first post)    Jul 21, 2024   (3 reactions) Now seeing the code I found the problem. In the Ideal_Text_Size method a Canvas is assigned to the Button, and this new assignment overrides the StateListDrawable definition. If you modify the Ideal_Text_Size method like below, commenting all lines concerned by the Canvas the Buttons behave as expec Bug? canvas.MeasureStringWidth return wrong value - Erel (first post)    Feb 10, 2015   (1 reaction) Canvas.MeasureStringWidth calls the native Paint.measureText method to measure the width.
After I removed the following line:
Label1.Width=Label1.Width-1dip
I see a difference of less than 1dip between the two results. It seems like a rounding error as suggested by the link @stevel05 posted.
Note B4A Question Canvas measure string width without designer's AutoScale - KZero    Mar 21, 2020 Label1.Width=cnv.MeasureStringWidth(Label1.Text,Label1.Typeface,Label1.TextSize)
if the layout set to "AutoScaleAll" the result is accurate but when I disable it, it doesn't measure the string right
am I missing something? B4A Question MeasureStringWidth with csBuilder - Erel (first post)    Mar 26, 2019 Canvas.MeasureStringWidth expects a string, not a CharSequence (CSBuilder). It will ignore the string attributes.
I guess that the simplest solution will be to add a small gap as a compensation for this. B4A Question set label height based on its text length - ronell (first post)    May 12, 2018   (1 reaction) why are you using MeasureStringHeight if you want to set label based on its length?
try changing your code to this
itmheight = Canvas1.MeasureStringWidth(msggtext, Typeface.DEFAULT, globalfontsize) Page: 1   2   3   4   5   6   7   Powered by ColBERT |