java - 在 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>
解决方案
您可以考虑使用此处回答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" />
您可以在此处查看答案以获得更好的理解。
推荐阅读
- java - 如何计算地图的最小/最大键?
- swift - 如何在 WatchOS 中使用背景视图填充整个 Button 区域?
- wso2 - WSO2 代理服务 XML Xpath
- amazon-cloudfront - 如何为 EC2 网站配置 route53 和 cloudfront
- python - Python中递归定义的超操作序列
- python - 在 Mac 上启动电子应用程序后,硒网络驱动程序挂起
- sql-server - SQL Server:始终加密(尝试在加密列中插入值时出现数据类型冲突错误)
- c++ - pthread 执行时间比顺序执行时间差
- aws-config - 为什么此 AWS Config 规则没有可用的结果?
- arduino-c++ - 对字符使用 XOR 作为简单的校验和;一个字符只是一个字节吗?