I have a layout for an App Widget which has a 3x3 grid of rotated TextViews:
<LinearLayout
style="@style/WidgetButtonLayout"
android:id="@+id/widget_buttons_text_port" >
<LinearLayout style="@style/WidgetButtonRow">
<TextView
style="@style/WidgetButton.Text"
android:rotation="-90"
android:id="@+id/upperLeft_text_port" />
<TextView
style="@style/WidgetButton.Text"
android:rotation="-90"
android:id="@+id/upperMiddle_text_port" />
<TextView
style="@style/WidgetButton.Text"
android:rotation="-90"
android:id="@+id/upperRight_text_port" />
</LinearLayout>
<LinearLayout style="@style/WidgetButtonRow">
<TextView
style="@style/WidgetButton.Text"
android:rotation="-90"
android:id="@+id/middleLeft_text_port" />
<TextView
style="@style/WidgetButton.Text"
android:rotation="-90"
android:id="@+id/middleMiddle_text_port" />
<TextView
style="@style/WidgetButton.Text"
android:rotation="-90"
android:id="@+id/middleRight_text_port" />
</LinearLayout>
<LinearLayout style="@style/WidgetButtonRow">
<TextView
style="@style/WidgetButton.Text"
android:rotation="-90"
android:id="@+id/lowerLeft_text_port" />
<TextView
style="@style/WidgetButton.Text"
android:rotation="-90"
android:id="@+id/lowerMiddle_text_port" />
<TextView
style="@style/WidgetButton.Text"
android:rotation="-90"
android:id="@+id/lowerRight_text_port" />
</LinearLayout>
</LinearLayout>
Where the styles are:
<style name="WidgetButtonLayout">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:orientation">vertical</item>
<item name="android:weightSum">3</item>
</style>
<style name="WidgetButtonRow">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">horizontal</item>
<item name="android:layout_weight">1</item>
<item name="android:weightSum">3</item>
</style>
<style name="WidgetButton">
<item name="android:layout_weight">1</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_margin">1dp</item>
<item name="android:gravity">center</item>
</style>
<style name="WidgetButton.Text">
<item name="android:textSize">15sp</item>
<item name="android:text">@string/button_settings</item>
<item name="android:textColor">@color/widgetButtonText</item>
<item name="android:background">@color/transparent</item>
</style>
This works fine, except that the text in each of the grid boxes wraps based on the unrotated width, not the rotated width, so that text is wrapped when there is space for it not to be... see e.g. the top-left grid box in the widget below:
Any idea how to fix this? I did think about just using a fixed and wider-than-needed TextView but the problem here is that the TextView is dynamically sized based on a grid layout.
EDIT note that since this is set within the context of an App Widget, this layout is for a RemoteViews and I cannot use setRotation()
to set the rotation programmatically on the TextView (see here) and other similar options are likewise limited.