0

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>
BArtWell
  • 4,118
  • 8
  • 58
  • 92

2 Answers2

1

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.

Zsombor Erdődy-Nagy
  • 16,546
  • 16
  • 74
  • 101
1

If you change the height programmatically you can define a formula and calculate the size of the text. It's the unique way, I think.

You may implement a custom view and define the size in function of parent's height.

Exist a kind of unit that could be util, sp (Scale-independent Pixels). But this scale with the size of the text set in the system.

BenMorel
  • 30,280
  • 40
  • 163
  • 285
JMPergar
  • 1,856
  • 1
  • 19
  • 21