【问题标题】:TextView in HorizontalScrollView not scrolling automatically when text is added添加文本时,Horizo​​ntalScrollView 中的 TextView 不会自动滚动
【发布时间】:2017-05-01 04:03:35
【问题描述】:

我有一个接受字符串的 TextView,我希望 TextView 自动滚动到右侧添加的最后一个文本。 ScrollView 可以工作,但是当它超出 TextView 的视野时,我必须手动滚动到最后添加的文本。请帮忙。

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.5"
        android:fillViewport="true"
        android:scrollbars="none">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:scrollHorizontally="true"
            android:textColor="@android:color/black"
            android:textSize="24sp" />
    </HorizontalScrollView>

【问题讨论】:

    标签: android xml textview horizontalscrollview


    【解决方案1】:
    yourScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
    

    【讨论】:

      【解决方案2】:

      我通过使用 EditTextView 而不是 TextView 解决了这个问题,并通过将 keyListener 设置为 null 来禁用 focusEnabled 以实现普通 TextView 的行为,并像我想要的那样自动滚动。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多