I have layout, which contain two parts: header and body. Header contain TextView and image. Header height can be changed programmatically. And header’s image and text must be scaled respectively. Image scaling ok, but text doesn’t want scaling. Is it possible on Android and how to do this?
My layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="UseCompoundDrawables" >
<TextView
android:id="@+id/title_text"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/app_name" />
<ImageView
android:id="@+id/edit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/edit"
android:src="@drawable/widget_edit" />
</LinearLayout>
<TextView
android:id="@+id/content_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
I don’t think that this is viable with the default TextView – at least not without some hacking.
I’d try using a custom View class for this, and draw the text on its Canvas. During the draw call, you know the exact width and height of the canvas and draw text with the appropriate font size.