I would love to know if it is possible to rotate a TextView inside of a ConstraintLayout but at the same time rotate its Constraint Bounds (i don't know if that's what they're called). As you can see in the image below, i've rotated the TextView using android:rotation="-90"
to rotate it vertically but its bounds don't follow the rotation thus making positioning it correctly impossible. Does anybody have any idea on how to go about doing that? All stack posts so far just refer to rotating the TextView.
Asked
Active
Viewed 1,289 times
3

Vadim Kotov
- 8,084
- 8
- 48
- 62

Stelios Papamichail
- 955
- 2
- 19
- 57
-
Even though the _TextView_ is rotated, its bounds do not rotate. That is what you are seeing. If you constrain another view to the rotated view's top or bottom, you will see the new view is constrained to the rotated view's top or bottom in its _unrotated_ state. (This also happens with _translationX_ and _translationY_.) If you can specify what you are trying to do, exactly, maybe someone can help. – Cheticamp Dec 09 '19 at 02:43
-
@Cheticamp I just want to constraint the TextView vertically to the right side of the screen but its bounds after the rotation get in the way (since they leave such a big gap between the text and the bounds) – Stelios Papamichail Dec 09 '19 at 11:09
-
Take a look at [this answer](https://stackoverflow.com/a/29736586/6287910) on Stack Overflow. It looks like you will need to use either a custom _TextView_ or use a square _TextView_ if you don't need a background. – Cheticamp Dec 09 '19 at 12:10
-
I tried both of these (using the link you provided) but neither seem to work since this is a ConstraintLayout. Is it even possible to write a custom TextView class that can manipulate the view's bounds in a ConstraintLayout? – Stelios Papamichail Dec 09 '19 at 13:15
-
It's trickier than I thought. I came across an alternate implementation for a vertical view that works with _ConstraintLayout_. (At least in my quick test.) Here is a link to the GitHub code: https://github.com/yoog568/VerticalTextView/blob/master/src/com/yoog/widget/VerticalTextView.java – Cheticamp Dec 09 '19 at 16:19
-
The only issue I see with this code is that the text does not display in the designer. The text does display in an emulator. – Cheticamp Dec 09 '19 at 16:21
-
It's true that the text doesn't show up in the designer (most of the time) but it achieves what i need. Thank you very much. Would you mind adding it as an answer so i can accept it? – Stelios Papamichail Dec 09 '19 at 19:22
-
I posted a [project](https://github.com/Cheticamp/VerticalTextView) on GitHub that has a fix to the first answer if you are interested. It's a little simpler than the second answer. – Cheticamp Dec 10 '19 at 22:24
-
@Cheticamp Bookmarked already :) . Do you happen to know why there isn't a built in solution for this by Google? – Stelios Papamichail Dec 11 '19 at 11:51
-
1Don't know. We can just add it to the list. – Cheticamp Dec 11 '19 at 12:13
1 Answers
2
It seems that this answer should work which refers to this answer but this solution doesn't seem to work with ConstraintLayout. I haven't looked into why not.
I have had better success with this GitHub project that writes text along paths. The text does not show up in the layout designer, but it will appear in an emulator and on a device.

Cheticamp
- 61,413
- 10
- 78
- 131