[英]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.