添加 android:textIsSelectable 导致 TextView 自动滚动

And*_*dre 5 android scrollview textview android-studio

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/solutions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:lineSpacingMultiplier="1.2"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:textIsSelectable="true"
            android:textSize="18sp"
            tools:text="1.  1+2+3 = 6"/>
    </HorizontalScrollView>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

android:textIsSelectable="true"添加后TextViewTextView会自动滚动到底部。但是我不想要这种行为。

raf*_*007 -1

试试这个:添加

android:focusable="false"
android:focusableInTouchMode="false"

 <TextView
        android:id="@+id/solutions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:lineSpacingMultiplier="1.2"
        android:text="1.  1+2+3 = 6"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textIsSelectable="true"
        android:textSize="18sp" />
Run Code Online (Sandbox Code Playgroud)

解决方案的原因是:

当您使用 时android:textIsSelectable="true",您实际上是在调用TextView.setTextIsSelectable(true),这会同时调用View.setFocusableView.setFocusableInTouchMode....并导致scrollview自动滚动文本。

  • 这使得文本无法选择 (4认同)
  • 我确认这会使文本在 API 23 上无法选择,所以它没有用。 (4认同)