【问题标题】:Height of TextView is not increasing beyond screen heightTextView 的高度没有增加超过屏幕高度
【发布时间】:2021-10-13 07:31:33
【问题描述】:

问题:在android中将文本添加到文本视图时,当文本足够长以使文本视图高度大于屏幕时,文本视图只会将其高度增加到屏幕高度而不会继续超越屏幕。

要求:根据文本内容增加文本视图的高度。 是否可以在运行时更改文本视图的高度?

编辑 即使我在 XML 中更改了电视的高度(大于屏幕的高度) 我的电视高度仍然没有超过屏幕高度。

编辑 2 我通过使用画布绘制 TextView 来实现这一点。我不确定这有多有效。

【问题讨论】:

  • 你怎么能看到 textView 中不在屏幕上的部分呢?为什么不启用滚动?
  • 实际上它在回收站视图中实现了粘性标题,但我使用的是文本视图的覆盖,因为我想要可自定义的粘性标题和其他一些要求。因此我不能使用滚动。但我正在根据回收站视图的滚动更改文本视图的 y

标签: android textview


【解决方案1】:

来自 MavenCentral 的 AutofitTextView 库可以很好地处理这个问题。源代码托管在 Github(1k+ 星)https://github.com/grantland/android-autofittextview

app/build.Gradle

repositories {
    mavenCentral()
}

dependencies {
    compile 'me.grantland:autofittextview:0.2.+'
}

在代码中启用任何扩展 TextView 的 View:

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"
    />

【讨论】:

  • 除了图书馆还有什么办法
猜你喜欢
  • 2017-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多