android - TextView 的高度没有增加超过屏幕高度
问题描述
问题:在 android 中将文本添加到文本视图时,当文本足够长以使 textview 高度大于屏幕时,textview 只会将其高度增加到屏幕高度而不超出屏幕。
要求:根据文本内容增加文本视图的高度。是否可以在运行时更改文本视图的高度?
编辑 即使我在 XML 中更改了电视的高度(大于屏幕的高度),我的电视高度仍然没有超过屏幕高度。
编辑 2 我通过使用画布绘制 TextView 来实现这一点。我不确定这有多有效。
解决方案
来自 MavenCentral 的 AutofitTextView 库很好地处理了这个问题。源代码托管在 Github(1k+ 星)上,位于https://github.com/grantland/android-autofittextview
应用程序/构建.Gradle
repositories {
mavenCentral()
}
dependencies {
compile 'me.grantland:autofittextview:0.2.+'
}
在代码中启用任何扩展 TextView 的视图:
AutofitHelper.create(textView);
在 XML 中启用任何扩展 TextView 的视图:
<me.grantland.widget.AutofitLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
/>
</me.grantland.widget.AutofitLayout>
在代码或 XML 中使用内置的 Widget:
<me.grantland.widget.AutofitTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
/>
推荐阅读
- c++ - c ++构造函数传递对基类对象的引用
- php - How get previous date from today in mongodb php?
- java - 由于升级标头无效,握手失败:null
- linux - 使用 Find 命令剪切日期以选择日期
- dictionary - 固定大小的Golang并发访问映射/数组
- java - Jsp调用重定向管理
- python - getText() vs text() vs get_text()
- r - 当 data.table := 是最后一次操作时,R 函数不返回任何内容而不是 data.table 对象
- firebase - Firebase:无法配置触发器提供程序/cloud.storage/eventTypes/object.change
- javascript - 通过将它移动到应用程序的 src 文件夹中来读取库 redux