【问题标题】:Adding android:textIsSelectable causes TextView to autoscroll添加 android:textIsSelectable 导致 TextView 自动滚动
【发布时间】:2017-03-13 10:03:52
【问题描述】:
<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>

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

【问题讨论】:

    标签: android android-studio textview scrollview


    【解决方案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" />
    

    解决的原因是:

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

    【讨论】:

    • 这使得文本无法选择
    • 请告诉我们更多关于您的想法。
    • 虽然此代码可能会回答问题,但提供有关 如何 和/或 为什么 解决问题的附加 context 将改善答案的长度长期价值。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人!请edit您的答案添加解释,并说明适用的限制和假设。
    • 我确认这会使 API 23 上的文本无法选择,所以它没用。
    猜你喜欢
    • 2013-11-18
    • 1970-01-01
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    相关资源
    最近更新 更多