I have a ConstraintLayout with some elements including an AppCompatTextView. Also, I am using app:autoSizeTextType="uniform"
in the AppCompatTextView to resize it according to the screen size (so, to make this work the AppCompatTextView width and height is 0dp (match_parent)) . The problem is that to make the text look a normal size in a 5" and 6" devices, I have added a layout_marginTop
and a layout_marginBottom
to make the layout of the AppCompatTextView smaller so that the AppCompatTextView size is resizing to a smaller size as its layout is smaller. The problem is that in small devices like 3.7" or 4" the AppCompatTextView gets cropped because of its layout because of the layout_margin is so big for that screen density that the text doesn't fit.
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tev"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="start"
android:text="@string/strng"
app:autoSizeTextType="uniform"
app:layout_constraintBottom_toBottomOf="@id/dr2"
app:layout_constraintEnd_toStartOf="@id/dlo"
app:layout_constraintStart_toEndOf="@id/miu"
app:layout_constraintTop_toTopOf="@id/cra"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
/>
See how the AppCompatTextView crops (The text is "Example TextView"):
I have seen that a possible solution could be to set app:autoSizeMinTextSize
to a small dp, but I have thought that it could be a better solution to set a dynamic layout margin according to the screen size so that the layout margin adapts to the screen size, could that be a good solution?