Home > Software design >  How to align two TextViews to make them read like a sentence
How to align two TextViews to make them read like a sentence

Time:08-30

I have a ConstraintLayout with two TextViews. I'm currently trying to align & constrain the two TextViews in order to make them read like a sentence in ConstraintLayout.

When TextView 1 gets long, I want TextView 2 to wrap to the next line, so that together - the two TextViews still appear as one piece of text.

The reason I'm doing this with separate TextViews, is that the my first and second textviews have different sources of data and are bound to separate fields in my ViewModel.

Please see the photo below:

enter image description here

Is this possible in ConstraintLayout or any of the other Layouts?

CodePudding user response:

Each Android view fills a continuous area on a screen. Your second TextView violates this characteristic insofar as it will have two disjointed areas and that is not permitted.

I suggest that you use a single TextView and observe the two sources of data to update the view. You might be able to use something like MediatorLiveData to do this.

CodePudding user response:

Both of the answers listed on this question are great and could potentially work, thanks!

For my specific use case, I found that using a FlexboxLayout, was the best solution: https://android-developers.googleblog.com/2017/02/build-flexible-layouts-with.html

  • Related