Skip to content
Commit d4082bb9 authored by Andrei Stingaceanu's avatar Andrei Stingaceanu
Browse files

AutoSize TextView - correct pixel transformations

When configuring a TextView to auto-size via min/max/granularity
do the calculations in float pixels and only convert to int (via
rounding, see TypedArray#getDimensionPixelSize) to produce the
final text size values to be used by the auto-size algorithm.
This is because the previous version where the values were
initially directly converted to pixels and only after used in
calculations was losing precision and was not consistent with how
we deal with preset configuration (and the developer
expectations).

Practically

textView1.setAutoSizeTextTypeUniformWithConfiguration(10, 20, 2,
        TypedValue.COMPLEX_UNIT_SP)

and

textView2.setAutoSizeTextTypeUniformWithPresetSizes(
         new int[] {10, 12, 14, 16, 18, 20},
         TypedValue.COMPLEX_UNIT_SP);

produce exactly the same values in pixels to choose from when
auto-sizing (on any device) =>
(TextView#getAutoSizeTextAvailableSizes())

Bug: 38185233
Bug: 37265610
Test: attached in the same topic
Change-Id: I95cbbf4674e98f080d7752ae350df26b4adf31b4
parent ab516db3
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment