繁体   English   中英

android TextView中的文本溢出

[英]Overflowing of text in android TextView

我在Android上使用TextView遇到一个相当奇怪的错误。 文本可以随机流过TextView的顶部边框,然后用户与其交互。 当TextView随动画更改其高度(单击时会放大和缩小)时,似乎会发生这种情况。

因此,它的外观如下(查看使用android dev工具启用的边框绘图,并且我已经用红色标记了TextView的边框) http://s7.postimage.org/c1ynrbwjv/so_full.png

我试过调用invalidate()postInvalidate() ), requestLayout()并重置TextView的重力
我还尝试重写扩展和收缩动画,以使用getLayoutParams()。height设置高度,而不是setMaxHeight()
最后,我将TextView放入LinearLayout(将TextView的高度设置为layout_height =“ wrap_content”),然后展开/缩小LinearLayout而不是TextView(因此TextView的边界不会直接改变)。 但是,您可以猜测,这没有帮助。

TextView布局(BoardPostText扩展了TextView):

<my.package.view.BoardPostText
    android:id="@+id/postText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/postTitle"
    android:clickable="true"
    android:linksClickable="true"
    android:longClickable="true"
    android:maxHeight="@dimen/post_image_max_height"
    android:paddingLeft="5dp"
    android:textColor="@color/post_data_text_color"
    android:textSize="@dimen/post_data_text_size"
    android:textColorLink="@color/post_link_color" />

TextView的代码https://gist.github.com/d47e8eafb1bcff7c8db1

我发现发生此类行为,然后在超链接上发生了MotionEvent。 因为只需要跨度即可单击,所以我做了这样的解决方法:

public static class JustClickableMethod extends LinkMovementMethod {

    public static MovementMethod getInstance() {
        return new JustClickableMethod();
    }

    @Override
    public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {

        int action = event.getAction() & MotionEvent.ACTION_MASK;

        if( action != MotionEvent.ACTION_UP ) {

            return true;
        }

        return super.onTouchEvent(widget, buffer, event);
    }

}

将此移动方法设置为TextView后,可单击范围仍会发生onClick()事件,但文字流动的错误消失了。

我认为这是因为LinkMovementMethod是“一种移动方法,该方法将遍历文本缓冲区中的链接并在必要时滚动 。支持使用DPad Center或Enter单击链接。”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM