1

I have a TextView. I really can't get why wrap_content doesn't work, or sometimes match constraint does the trick whereas the issue is about wrapping. In this case, I can't make the message appear in my screen. I don't mind if it's a singleline or the exclamation pops in the next one, I want to grasp the nature of what to use in this situation or any other that arises.

<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="match_parent"
android:layout_height="match_parent"
tools:layout_height="match_parent">

<TextView
    android:id="@+id/levelMathQuizTextVIew"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:fontFamily="cursive"
    android:gravity="center"
    android:text="Level 1!"
    android:textAlignment="center"
    android:textColor="@color/black"
    android:textSize="100sp"
    android:textStyle="bold|italic"
    app:layout_constrainedHeight="true"
    app:layout_constrainedWidth="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

horizontally clipped rendering

I've seen similar problems, it seems app:layout_constrainedHeight="true" or app:layout_constrainedWidth="true" did the trick, but I haven't seen any difference using them.

The "Level 1" looks like that on my mobile phone and on the emulator. I would like to post this text without it being trimmed and really get to know why it is clipped by using either match constraint or wrap_content.

greybeard
  • 2,249
  • 8
  • 30
  • 66
  • My guess is that this is a font problem. If you eliminate `android:fontFamily="cursive"`, do you get better results? – CommonsWare Apr 17 '21 at 18:45
  • @CommonsWare Yes, when I remove it everything goes as expected! Is there such thing as a "malfunctioning" font and code was fine to begin with? Another workaround would be to lower the size, but what I wanted most was to find the issue. – Chris Karasoulas Apr 17 '21 at 20:05
  • 1
    It feels like the bounding boxes of the letters that Android is using are not taking into account the overlap that `cursive` applies. For example, if you look at your screenshot, the top of the `1` overlaps the bottom of the `!`. This probably gets into font kerning, which is getting *way* outside my area. See https://stackoverflow.com/q/28576797/115145 and https://stackoverflow.com/q/44074858/115145 for others who have fought this. Upshot: Android's font handling has issues. – CommonsWare Apr 17 '21 at 20:19
  • @CommonsWare Thank you for your help! I'd like to mark this as an accepted answer, but it seem this is a comment. Need to get used to this forum – Chris Karasoulas Apr 18 '21 at 07:32
  • I am guessing that those other two questions are for the same problem that you are seeing, so I marked them as duplicates, to steer future visitors to them. – CommonsWare Apr 18 '21 at 11:21

0 Answers0