android TextView ellipsize 只显示一个点 解决方案

android 自带空间TextView在部分手机上设置单行显示时只显示一个点


解决方案

 


布局




    

        

        
    


    

        

        

        
    




holder.moneyll.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            holder.houseName.isOverFlowed(room.getRoomName().trim(),
                    ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth() - holder.moneyll.getMeasuredWidth());


public class CustomTextViewDot extends TextView {

    public CustomTextViewDot(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public CustomTextViewDot(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomTextViewDot(Context context) {
        super(context);
    }

    public void isOverFlowed(String value, int widthLL) {
        Paint paint = getPaint();
        float width = paint.measureText(value);
        widthLL = widthLL - getPaddingLeft();
        if (width > widthLL) {
            for (int i = value.length() - 4; i > 0; i--) {
                width = paint.measureText(ATStringUtil.concatString(value.substring(0, i), "..."));
                if (width <= widthLL) {
                    setText(ATStringUtil.concatString(value.substring(0, i), "..."));
                    break;
                }
            }
        }
    }
}




你可能感兴趣的:(android,TextView,ellipsize)