TextView的最后一行绘制一半 [英] TextView last line drawn in half

查看:236
本文介绍了TextView的最后一行绘制一半的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextView其高度是动态的。我想要设置的最后一行不会是可见,如果它不能被完全绘制。
截图

之所以高度是动态的是,它是在一个AppWidget使用,并且一个appwidget的大小不是在不同的设备是相同的。正因为如此,你不能衡量的TextView或不能使用一个TextView的子类。
链接

这是我用现在基本上。当我把一个长的文本到TextView的最后一行看起来很难看。

 <的LinearLayout
机器人:ID =@ + ID / widgetContent
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>
<的TextView
    机器人:ID =@ + ID / SG
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>


解决方案

试试这个

 涂料粉刷=新的油漆();
//设置漆TextView的当前所有文本属性。喜欢文字的大小,面等,textPixelLenght = paint.measureText(MTEXT);
INT textviewWidth = mTextView.getMeasuredWidth();
INT numberOfLines = textPixelLenght / textviewWidth ;;INT textlineHeight = textview.getLineHeight();
如果(textlineheight * numberOfLines> textviewHeight){
    //文本超越textviews高度。使用Ellipsize文
    // TextUtils.ellipsize(PARAMS);
}

I have a TextView which height is dynamic. I want to set that the last line wouldnt be visible if it cannot be fully drawn. screenshot

The reason why height is dynamic is that it is used in an AppWidget, and the size of an appwidget is not the same on different devices. Because of this you cannot measure the TextView or cannot use a subclass of a TextView. link

This is what I use now basically. When I put a long text into the TextView the last line looks ugly.

<LinearLayout
android:id="@+id/widgetContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
    android:id="@+id/sg"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>
</LinearLayout>

解决方案

Try this

Paint  paint = new Paint();
// set paint with all current text properties of the textview. like text size, face etc,

textPixelLenght = paint.measureText(mText);
int textviewWidth = mTextView.getMeasuredWidth();
int numberOfLines = textPixelLenght /textviewWidth;;

int textlineHeight = textview.getLineHeight ();
if (textlineheight * numberOfLines > textviewHeight) {
    // text going beyond textviews height. Ellipsize the text using
    // TextUtils.ellipsize(params);     
} 

这篇关于TextView的最后一行绘制一半的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆