1

I'm trying to make an app (well, part of an app) which takes an input string from the user and displays it fullscreen, in a different fragment. Which I've got working, but using autoSize on it makes the text so big it gets wrapped, like this: Android screenshot showing the text "Moo!!!!!!!" split over multiple lines

Not all words get broken if they're small enough:
Android screenshot showing the text "moooooooooo and again", with the extended "moo" being split over multiple lines

Looking through the docs (and some web searching), these were the only XML attributes that seemed relevant:

android:breakStrategy="simple"
android:ellipsize="none"
android:hyphenationFrequency="none"

None of them seemed to change the behaviour. About the only thing I could find that makes a difference is android:singleLine="true" but that makes things worse:
Android screenshot showing the text "Moo" with only the first two letters visible
and I'm not sure I want to know how much worse that makes it when there's multiple words.

I've pared the fragment layout down to basically the minimum possible that I can think of:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    android:layout_gravity="center">

    <TextView
        android:id="@+id/frag_big_text_text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/big_text_background"
        android:gravity="center"
        
        android:keepScreenOn="true"
        android:clickable="true"
        android:longClickable="true"
        android:focusable="true"
        android:textColor="@color/big_text_foreground"
    
        android:breakStrategy="simple"
        android:ellipsize="none"
        android:hyphenationFrequency="none"
        
        app:autoSizeTextType="uniform"
        app:autoSizeMaxTextSize="240sp"
        app:autoSizeMinTextSize="14sp"
        app:autoSizeStepGranularity="1px"
        
        tools:gravity="center"
        tools:targetApi="m"
        tools:text="BIG TEXT HERE"/>
    
</FrameLayout>

I know I could set the autoSizeMaxTestSize to something lower that should fit most phone screens, but then it won't fill the screen on a tablet (and don't worry about targeting m, my AVD is set to match the specs of my phone, which is on API 29). The code that sets the current text is also pretty simple:bigTextView.text = messageList[index] (and it's definitely not a problem with the list it's pulling from, since I tried hard coding it with bigTextView.text = "thisisareallylongword", same result).

I'm hoping this is one case where I'm missing something obvious and don't have to reinvent the wheel. Wheels aren't my area of expertise, I figured that out when I had to fix a broken pip install.

But whatever reinvention or stupid intervention is required, can anyone help me out?

Slashee the Cow
  • 173
  • 2
  • 8

0 Answers0