0

I have a TextView that is used in a RemoteView. But the text in there varies and so sometimes it is simply too long and is partially cut off. I want my text to automatically scale so that it fits into the TextView. I am using the Support Library, but app:autoSizeTextType="uniform" won't work in a RemoteView. Is there another way?

Here's the xml-code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="256dp">

    <TextView
        android:id="@+id/myTextView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:gravity="center_vertical|center_horizontal"
        android:text="Some long text here."
        android:textSize="26sp" />
</RelativeLayout>
Reaz Murshed
  • 21,071
  • 12
  • 69
  • 87
Elias
  • 21
  • 6

1 Answers1

0

You might consider using a custom TextView as answered here.

I am not quite sure about auto resizing does not work with RemoteView. However, as shown in the developer documentation you might consider giving a specific height of the TextView in your case like the following.

<TextView
      android:layout_width="match_parent"
      android:layout_height="200dp"
      app:autoSizeTextType="uniform" />

You might also consider using android.support.v7.widget.AppCompatTextView for having the support for previous versions as long as you are using support library 26.0.0.

<android.support.v7.widget.AppCompatTextView
      android:layout_width="match_parent"
      android:layout_height="200dp"
      app:autoSizeTextType="uniform" />

You might check the answer here for better understanding.

Reaz Murshed
  • 21,071
  • 12
  • 69
  • 87
  • 1
    Thanks for the answer, but you can't use custom `Views` in `RemoteViews`. You also can't use `android.support.v7.widget.AppCompatTextView`. And changing the height to a fixed value won't change anything either. – Elias Jun 04 '18 at 17:49