首页 > 解决方案 > 每次更新视图时,Android 垂直滚动视图会自动移动到顶部

问题描述

我在 Android 中的滚动条,每次更新我的 ConstraintLayout 中的 TextView 时向上滚动。许多 TextView 每秒都会使用来自外部设备的值进行更新,并且滚动条每秒都会返回到顶部位置。我只是希望对于 TextView 的每次更新,都没有滚动。滚动只能在我触摸时发生。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/ScrollView_example"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:descendantFocusability="beforeDescendants"
    android:fillViewport="true" >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/Constraint_example"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txt1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="16dp"
            android:text="My TextVIEW1"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"  />

请问,有人可以帮我吗?非常感谢。

标签: androidscrollbar

解决方案


推荐阅读