How to Create a Magic Text That Always Fits Its Container - Jetpack Compose Tutorial

preview_player
Показать описание
Ever had a text that was sometimes too large to fit in its container on some devices? In this video I'll show you how you can create an auto-scaling text that will surely always fit.

⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:

💻 Let me be your mentor and become an industry-ready Android developer in 10 weeks:

Subscribe to my FREE newsletter for regular Android, Kotlin & Architecture advice!

Join this channel to get access to perks:

Get the source code for this video here:

Join my Discord server:

You like my free content? Here you can buy me a coffee:
Рекомендации по теме
Комментарии
Автор

A definitely nice tutorial and it works, sure, but shouldn't there be a way to compute the exact fontSize value on the first pass, instead of "guessing"? Also would need adjustments if the initial size is smaller and we want to, on the contrary, up-size it

JxDGT
Автор

So how does it work with rotating the device?
I understand the remember "saves" the style but we have to refresh that since a rotation might change the width.

davidgreenwitch
Автор

Great explanation thank you.
However I think the style.fontSize.isUnspecified line isn't right/causes a bug? Since it's checking style and not resizedTextStyle if it's triggered once it will be triggered every time, setting the resizedTextStyle font size to default every time causing an infinite loop?

MonkeyMan
Автор

What a timing, I had just developed my AutoScaleText and this video shows up . Thanks, but what if text is updated later on?

Neo-baybobey
Автор

Hey philipp, this workaround doesn't seem to increase font size when there's more space available, only reduces it, how can i achieve such behavior? similar to xmls "android:autoSizeTextType" property. Thx in advance!

David-zbbr
Автор

I just want to change a text.. android studio has gotten ridiculous over the years ...

jaxxrr
Автор

Take some rest brother... anyways kudos to you commitment

pemmasanirajesh
Автор

Thanks a lot Philipp. You literally save me, last 3 days i am dealing with this problem.

Could you please make another video to highlight text by button click.

fsfaysalcse
Автор

It always seemed odd to me that Android provides "density-independent pixels" (DP) that sort of address this rescaling concern, but not completely.

ubersticks
Автор

Great, very useful: but i still have an issue with wrapping the content . Tthe Text component size doesn't changet to wrap the content which now is smaller because of a smaller font. You now get what looks like padding on the right

nikitah
Автор

Hiii Philip, there is a problem with the code when used in a LazyColumn/Row and the component is recomposed while scrolling. The text disappears and reappears when the component is visible again in a list. It seems to be a problem with how modifier.drawWithContent handles the recomposition.

eru
Автор

as a beginner on jetpack compose I love this kinda of videos

elohimalves
Автор

Hi Philip, it surprised me to see the title of this video because I've been struggling with something similar but for compose desktop. The difference is that I want for the text to be resized when the window size changes (so yeah dinamically). I have tried a very similar solution to this one, but defined two key points to solve in order for the custom layout to really work.
- The first one is "when" (or better said, which hook to use) to reset the shouldDraw variable, in order for the layout to admit redrawing
- The second one is how to know the text is small enough to be upsized, since the overflow only happens when the text is bigger than expected

Just playing philosophical here (unless you know the answer, then please reply hehe), your content is great, keep it up!

arielgoska
Автор

Hi Philipp, I want to join your members-only to be able to watch some members-only videos, however i can't seem to find the join button on your channel page. any help?

includejoe
Автор

Please make a video about best practices of using ViewModel, Flow and States in compose

ahmadrezasariaslani
Автор

Hi Philipp. ¿Can you re-activate KMM25 code for KMM course? Very thanks for all your hard work creating this coruses and videos :)

RC-bv
Автор

Have you ever used the libraries "sdp" and "ddp" from Intuit to provide scalable dp and scalable sp? They seem to address the same problem (specified SP or DP do not scale with screen size)

ubersticks
Автор

Hi Philipp, I want to join your members-only to be able to watch some members-only videos, however i can't seem to find the join button on your channel page. any help?

includejoe
Автор

That's amazing I was trying to implement one that would fill the entire dedicated space I just changed didOverflowWidth to didOverflowHeight and softWrap = true and set the font size to a very high size like 100.sp now it works just like I want it.
Thank you!

Hadibtf
Автор

Hi Philipp, I want to join your members-only to be able to watch some members-only videos, however i can't seem to find the join button on your channel page. any help?

includejoe