Android 缩小子视图的高度相同

Android 缩小子视图的高度相同,android,view,kotlin,android-nestedscrollview,Android,View,Kotlin,Android Nestedscrollview,我试图在NestedScrollView中的TextView中显示文本,以便在缩小TextView后显示比屏幕大的文本。 这是我的密码- val content = findViewById(R.id.content) as TextView content.setText(R.string.large_text) content.viewTreeObserver.addOnGlobalLayoutListener { L

我试图在
NestedScrollView
中的
TextView
中显示文本,以便在缩小
TextView
后显示比屏幕大的文本。 这是我的密码-

        val content = findViewById(R.id.content) as TextView
        content.setText(R.string.large_text)

        content.viewTreeObserver.addOnGlobalLayoutListener {
            Log.d("Height", content.height.toString())//1584:6501
            val factor = 1584f / 6501;
            content.scaleX = factor;
            content.scaleY = factor;
        }
其中我的设备屏幕高度为
1584px
TextView
的内容高度为
6501px

问题是
NestedScollView
sill在将
TextView
的高度缩小到设备屏幕高度后会滚动

我还尝试在TextView及其父对象NestedScrollView上调用invalidate()和requestLayout(),但没有成功<代码>滚动视图保持滚动

我还尝试扩展
TextView
并将
onMeasure()方法重写为

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        val parentWidth = MeasureSpec.getSize(widthMeasureSpec)
        val parentHeight = 1584// MeasureSpec.getSize(heightMeasureSpec)
        this.setMeasuredDimension(parentWidth, parentHeight)
    }
但是,
NestedScrollView
停止滚动,
TextView
中的内容没有显示所有内容。可能
TextView
与屏幕的高度相同,因此没有显示所有文本

如何强制“TextView”在缩放后采用缩放高度,以便
NestedScrollView
不滚动? 我们将非常感谢您的帮助,提前谢谢

编辑 这是我的XML代码-

<FrameLayout 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="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.admin.canary.KotlinActivity"
    tools:showIn="@layout/activity_kotlin">
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </android.support.v4.widget.NestedScrollView>
</FrameLayout>

您的观察只是实现的行为。将转换应用于视图实际上不会更改视图的任何属性。因此,在您的情况下,视图仅在
onDraw()
中按比例缩小,而实际大小不变

然后重写
onMeasure()
方法将为文本视图本身设置一个固定大小,而不会将文本调整到此大小。它只是对文本本身进行了剪切

您还应该考虑到,文本视图已经可以滚动,或者至少嵌套的滚动视图应该定义
android:layout\u height=“match\u parent”



有效地拟合文本视图并不太容易。你可以用一些图书馆来做这个。支持您正在寻找的行为。您必须用
com.vj.widgets.AutoResizeTextView
替换整个布局,并使其与屏幕大小相匹配。

使用层次结构查看器,确保哪个元素的高度大于您的屏幕。@ShadyAtef显然是文本视图,其内容(字符串)超过屏幕高度。好的,你能提供布局xml吗?我很感兴趣去调查。我想AutoFitTextView并不能解决我的问题。实际上,我正在尝试渲染CreateBookReader,在这里我使用TextView渲染单个页面。假设我有每个页面(html),它有720*1280维,文本大小为26px。如何在另一个屏幕上显示与上述尺寸不同的相同外观?我试着创建一个具有相同维度的文本视图,并缩放以适应其他维度的屏幕