I have a TextView within a HorizontalScrollView, as shown below. Currently, I am using a fixed text size. Now, I would like to calculate the maximum text size that I can use without the text size exceeding the height of the TextView. Note that the width of the text is not an issue, since the TextView is a child of the HorizontalScrollView, so the text becomes scrollable as soon it extends the allowable width.
<HorizontalScrollView
android:id="@+id/horizontal_scroll_view_equation"
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:fillViewport="true"
android:layout_gravity="right">
<LinearLayout
android:layout_gravity="right"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView
android:layout_marginRight="@dimen/spacing_medium"
android:layout_marginLeft="@dimen/spacing_medium"
android:id="@+id/text_view_equation"
android:background="@android:color/transparent"
android:gravity="center_vertical|right"
android:layout_gravity="right"
android:maxLines="1"
android:textSize="@dimen/font_xxxlarge"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
</HorizontalScrollView>
I've been looking into posts on StackOverflow and another forums, but I could only find posts that consider both the width and height.
Is there a simple solution to calculate the maximum text size based on the height of the TextView?
I actually found the answer myself. The solution is as follows. Firstly, I made a custom TextView, as shown below.
And then I used this TextView as child in my HorizontalScrollView, as shown below.