I’m having a problem with font scaling that happens only on some pixel devices. For some of my views that contain a text, i’m setting the view height in sp
. The reason for this is that i’m using the height of these views in some calculations and i need them to be fixed, but i can’t use dp
because otherwise text could get cut. So I use sp
so that my view would expand when i change the device’s text size.
This approach works on most devices, but i’ve noticed that on my pixel 8 (Android 14), when i change the text size, the views stay the same height. Only the texts inside the views expand which causes them to get cut and look horrible.
I’ve tried logging the actual value of the height and i can see that on other devices, they change, but on pixel 8 they don’t. For example:
On other devices, with default text size, 52sp
equal 160
and when i scale up the font, 52sp
changes to 223
. But testing on Pixel 8, the value for 52sp
is always the same, regardless of text size.
Does anybody know why this happens and how exactly does Pixel 8 handles font scaling? And also if there’s a way to be able to solve my problem?
For the sake of clarity, here’s a sample xml I’m trying to make work:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="101dp"
android:layout_height="52sp"
android:id="@+id/container">
...
Other views
...
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/title"
android:textSize="12sp"
android:ellipsize="end"
android:maxLines="1"
android:textAlignment="textStart"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/border_right"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
...
Other views
...
</androidx.constraintlayout.widget.ConstraintLayout>