Android Question Auto Adjust Label Textsize to Fit Label Width

Mahares

Expert
Licensed User
Longtime User
I use the entire code shown below to adjust the text size of the label to fit a smaller label width, but it is not working for me. If it is working for you then my problem lies in this line: #AdditionalJar: com.android.support:support-compat
What am I suppose to download or change? I have SDK manager 3.29. My Android.jar is: C:\Android\platforms\android-27\android.jar
Thank you

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

#AdditionalJar: com.android.support:support-compat

Sub Process_Globals
End Sub

Sub Globals
    Private lblDesc As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    lblDesc.Initialize("")
    Activity.AddView(lblDesc,20%x,20%y,150dip,40dip)
    lblDesc.TextColor=Colors.Red
    lblDesc.Text="This is a quite long text to fit label width by reducing it text size"
    SetAutoSizeBasedOnText(lblDesc)
End Sub

Sub SetAutoSizeBasedOnText(v As View)
    Dim jo As JavaObject
    jo.InitializeStatic("android.support.v4.widget.TextViewCompat")
    jo.RunMethod("setAutoSizeTextTypeWithDefaults", Array(v, 1))
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
have you tried to use Android.jar from api 28? Tools->Configure paths
It should be in C:\Android\platforms\android-28\ if you downloaded the newest components. BTW: The newest Version of SdkManager is 3.30 or 3.31 or so...
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Is there a way to adjust the text size of a label to fit the given label width without adding any additional libraries I just simply need it for one label. My project is already saturated with 3rd party libs and I am trying to avoid bloating it. My devices are either OS 5, 6 or 7 and B4A is 8.50. I have attached a very tiny project to demonstrate my need.
 

Attachments

  • AdjustViewTextSizeToFitWidth.zip
    8.1 KB · Views: 424
Upvote 0
Top