Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJegnesh Gehlot
5,452 PointsHow to rotate text in a textview by using xml?
I am trying to rotate text in a textview but its not aligning right. Here is the code:
<LinearLayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="59.5" android:background="@android:color/holo_red_light" android:orientation="horizontal" android:weightSum="4">
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:singleLine="true"
android:rotation="270"
android:layout_gravity="bottom"
android:gravity="center"
android:text="My Video Report"/>
</LinearLayout>
<ImageView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:layout_weight="3"
android:gravity="center"
android:src="@drawable/ic_stat_name"/>
</LinearLayout>
</LinearLayout>
2 Answers
Daniel Hartin
18,106 PointsHi Jegnesh
Interesting question. I have never used this property myself I have always manipulated views by painting them to a canvas as it allows greater flexibility about where and how I want things placed, that said however I looked up a few similar issues on stack overflow and it seems possible.
Have you tried altering the Linear layout to match_parent for both width and height so it fills the screen and then set the textview to wrap_content for both width and height. What i'm think is if the view fills both the width and height of the parent view it won't fit correctly when spun 207 degrees.
Sorry, it's not really much help.
Let me know if the above doesn't work and I will try to write a dummy application myself
Thanks Daniel
Jegnesh Gehlot
5,452 PointsDaniel, Thanks for your response. I was about to implement a canvas but then I found a post on stackoverflow that helped me achieve what I was looking for. Here is the link: http://stackoverflow.com/questions/2888780/is-it-possible-to-write-vertically-in-a-textview-in-android/12433475#12433475
But I appreciate your help and I personally think the best way to go is using canvas so I select your suggestion as best answer.
Thanks