【问题标题】:Automatically scale TextView text in RemoteView在 RemoteView 中自动缩放 TextView 文本
【发布时间】:2018-11-13 02:58:19
【问题描述】:

我有一个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>

【问题讨论】:

    标签: java android


    【解决方案1】:

    您可以考虑使用自定义TextView 作为answered here。

    我不太确定自动调整大小不适用于RemoteView。但是,如developer documentation 所示,您可能会考虑在您的情况下给出TextView 的特定高度,如下所示。

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

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

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

    您可以查看answer here 以获得更好的理解。

    【讨论】:

    • 感谢您的回答,但您不能在RemoteViews 中使用自定义Views。你也不能使用android.support.v7.widget.AppCompatTextView。将高度更改为固定值也不会改变任何内容。
    猜你喜欢
    • 1970-01-01
    • 2014-10-21
    • 1970-01-01
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 2012-02-26
    • 1970-01-01
    相关资源
    最近更新 更多