当线程为 运行 时,文本视图不会在屏幕上从左向右滚动

Text View not scrolling from left to right across screen when thread is running

我有一个问题,我的 textview 应该在一行中从左向右滚动,而当我 运行 线程时不会发生这种情况。当我评论我的线程函数时它 运行s 完美,但是当线程 运行s 时它开始缓冲。该线程只假设控制搜索栏,所以我不确定它为什么会影响 textview 元素。我已经提供了我的 xml 和 activity。 知道如何保持线程,但仍然有办法选择文本视图吗?

XML 文本视图代码-

<TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Long text goes here"
        android:textSize="25sp"
        android:textStyle="bold"
        android:textAlignment="center"
        android:layout_centerHorizontal="true"
        android:textAllCaps="false"
        android:textColor="@android:color/black"
        android:layout_marginTop="7dp"
        android:singleLine="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal" />

相关Activity个函数-

 private fun validateReceivedValues() {
    val title = intent.getStringExtra("title")
    songNameText.text = title
    songNameText.isSelected = true  //this allows the marquee to occur
    artistNameText.text = artist
    totalTime = duration

    thread()  //commenting this out means the text will marquee, otherwise by calling this it will constantly buffer every second
}

private fun thread() {
    val musicMethodsHandler = Handler()
    val musicRun = object : Runnable {
        override fun run() {
            if (musicBound) {
                positionBar.max = totalTime
                val musicCurTime = musicSrv!!.getSeek()
                positionBar.progress = musicCurTime
                val elapsedTime = createTimeLabel(musicCurTime)
                elapsedTimeLabel.text = elapsedTime
                val remainingTime = createTimeLabel(totalTime - musicCurTime)
                remainingTimeLabel.text = "-$remainingTime"
            }
            musicMethodsHandler.postDelayed(this, 1000)
        }
    }
    musicMethodsHandler.postDelayed(musicRun, 1000)
}

我能够通过将文本视图置于其自己的布局中来解决此问题,这样它就不会成为进度条的同级。希望有人发现此信息有用。

<LinearLayout
        android:id="@+id/marquee_text_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/logo">
        <TextView
            android:id="@+id/songname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Song"
            android:textSize="25sp"
            android:textStyle="bold"
            android:textAlignment="center"
            android:textAllCaps="false"
            android:textColor="@android:color/black"
            android:layout_marginTop="7dp"
            android:singleLine="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />
    </LinearLayout>