trencasostres Member Licensed User Longtime User Mar 18, 2013 #1 Hello, Does anyone know why the text is not vertically centered in the view when using larger text sizes? For example an edittext with height:120; width:260: text size:130 thanks.
Hello, Does anyone know why the text is not vertically centered in the view when using larger text sizes? For example an edittext with height:120; width:260: text size:130 thanks.
thedesolatesoul Expert Licensed User Longtime User Mar 18, 2013 #2 You need to set the gravity. Label.Gravity = Gravity.CENTERED_VERTICAL (or something like that)
trencasostres Member Licensed User Longtime User Mar 18, 2013 #3 Thanks, but I've tried it and does not work.
Erel B4X founder Staff member Licensed User Longtime User Mar 19, 2013 #4 The text layout is handled by the OS.
trencasostres Member Licensed User Longtime User Mar 19, 2013 #5 Does it mean that is this the way of how it works? And I can't to do anything? Thanks.
stevel05 Expert Licensed User Longtime User Mar 19, 2013 #6 It appears OK here (running on Bluestacks at least) I set up an edittext as you said and set Horizontal alignment to CENTER_HORIZONTAL all in the designer. Typeface : DEFAULT Style : NORMAL Horizontal Alignment : CENTER_HORIZONTAL Vertical Alignment : CENTER_VERTICAL Size 130 Text Color DEFAULT It looks as I'd expect. Do you see the cursor in the middle when the edit text is empty?
It appears OK here (running on Bluestacks at least) I set up an edittext as you said and set Horizontal alignment to CENTER_HORIZONTAL all in the designer. Typeface : DEFAULT Style : NORMAL Horizontal Alignment : CENTER_HORIZONTAL Vertical Alignment : CENTER_VERTICAL Size 130 Text Color DEFAULT It looks as I'd expect. Do you see the cursor in the middle when the edit text is empty?
klaus Expert Licensed User Longtime User Mar 20, 2013 #7 You should post your code or at least a smaller project showing the problem and a screenshot of what you get and tell us what exactly you expect. Otherwise impossible to give you any good advice. Best regards.
You should post your code or at least a smaller project showing the problem and a screenshot of what you get and tell us what exactly you expect. Otherwise impossible to give you any good advice. Best regards.
trencasostres Member Licensed User Longtime User Mar 21, 2013 #8 In the example attached, we can see how the vertical centering does not work well. The red line indicates the center of the view. Initially, the text should be centered. Could depend on the level of API? I'll keep trying. Attachments textsize.zip textsize.zip 7.3 KB · Views: 408
In the example attached, we can see how the vertical centering does not work well. The red line indicates the center of the view. Initially, the text should be centered. Could depend on the level of API? I'll keep trying.
klaus Expert Licensed User Longtime User Mar 21, 2013 #9 You need to take into account following parameters: - Font metrics - Padding, in your case with a ColorDrawable background there is no padding. Attached your modified test program. With big font sizes when the text becomes higher than the view the reference for the display seems to be the top of the character space. Best regards. Attachments textsize_1.zip textsize_1.zip 7.7 KB · Views: 427
You need to take into account following parameters: - Font metrics - Padding, in your case with a ColorDrawable background there is no padding. Attached your modified test program. With big font sizes when the text becomes higher than the view the reference for the display seems to be the top of the character space. Best regards.
stevel05 Expert Licensed User Longtime User Mar 21, 2013 #10 From the Android developers web site TextView: setGravity(int gravity) Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself. Click to expand... This only has effect if there is extra space in the field, otherwise it appears as Klaus has mentioned that the characters are set to the top position and is borne out by your test app.
From the Android developers web site TextView: setGravity(int gravity) Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself. Click to expand... This only has effect if there is extra space in the field, otherwise it appears as Klaus has mentioned that the characters are set to the top position and is borne out by your test app.
trencasostres Member Licensed User Longtime User Mar 21, 2013 #11 Thanks Klaus. I will study your contribution, although it is a little difficult to understand for me.
Thanks Klaus. I will study your contribution, although it is a little difficult to understand for me.
trencasostres Member Licensed User Longtime User Mar 21, 2013 #13 I am beginner in B4a and I need some time to digest your code. Also, I'm not English speaking. Thank you again.
I am beginner in B4a and I need some time to digest your code. Also, I'm not English speaking. Thank you again.