1

Is it possible to rotate views in XML with APIs previous to Honeycomb - maybe with the support package? Or is the only way to create a custom class, like described here Vertical (rotated) label in Android

Edit: What I need is a statically rotated view (specifically a TextView, but I guess it's enough to know how to do it with a View). Starting with honeycomb there's a rotation attribute which can be used in XML. I need something like that.

The only thing I have found until now is use an animation with duration 0 but this still moves a bit at start and I don't want that. I tried setting the views invisible and attaching a listener to the animation which makes them visible on animation finished callback, but that made strange results... that changed the position of the views, for some reason.

Community
  • 1
  • 1
User
  • 31,811
  • 40
  • 131
  • 232

2 Answers2

2

The best way is with the custom subclass implementation that you linked to, where you can rotate the canvas and resize the view appropriately. This ensures that the view bounds are also set to match the text that is drawn.

The only method of transforming views externally prior to HC is the animation framework, and applying an Animation to the view with a duration of 0 and fillAfter set to true will work, but you may notice flickering on some devices as often the view will render normally on its first frame and then animated to its final position from that point onward. You can work around this by hiding the view and displaying it a bit late...but you can see how hacks are starting to stack up.

In addition, doing an Animation prior to HC will not transform the view bounds themselves, so you won't be able to neatly pack other views around this one because its position from a layout perspective will still be the rectangle calculated for the horizontal (non-rotated) text.

The simple subclass is definitely the preferred method.

HTH

devunwired
  • 62,780
  • 12
  • 127
  • 139
1

Is it possible to rotate views in XML with APIs previous to Honeycomb

There is RotateAnimation. However, depending on what you are trying to accomplish, that may not meet your needs.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I want to have a TextView rotated (static, not animated) 45 degrees. Found now this http://stackoverflow.com/questions/6952926/rotate-text-on-a-button?lq=1 it's an animation with duration 0, probably it works. – User Jun 14 '12 at 11:32