首页 > 解决方案 > 在 RemoteView 中自动缩放 TextView 文本

问题描述

我有一个TextView用于RemoteView. 但是里面的文字各不相同,所以有时它太长了,被部分截断了。我希望我的文本自动缩放以适合TextView. 我正在使用支持库,但app:autoSizeTextType="uniform"无法在RemoteView. 还有其他方法吗?

这是xml代码:

<?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>

标签: javaandroid

解决方案


您可以考虑使用此处回答TextView的自定义。

我不太确定自动调整大小不适用于RemoteView. 但是,如开发人员文档中所示,您可能会考虑在您的情况下给出一个特定的高度,TextView如下所示。

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

android.support.v7.widget.AppCompatTextView只要您使用支持库 26.0.0,您也可以考虑使用for 支持以前的版本。

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

您可以在此处查看答案以获得更好的理解。


推荐阅读