android 自定义TextView

针对系统TextView在文字不满一行时自动换行的问题,本文介绍了如何自定义一个TextView,确保只在一行无法完整显示时才进行换行。提供了相关代码示例和Demo下载链接。
摘要由CSDN通过智能技术生成

系统自带的控件TextView有时候没满一行就换行了,为了解决这个问题,自定义了一个TextView,只有一行显示不完全的情况下才会去换行显示,代码如下:

package com.open.textview;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;

/**
 * 不换行的TextView
 * @author Administrator
 *
 */
public class CusTextView extends View {
	
    protected float textSize=35;  
    protected float paddingLeft=0;
    protected float paddingRight=0;
    protected float paddingTop=0;
    protected float paddingBottom=0;
    
    protected float lineSpace=5; 
    protected int lineWidth=320;
    protected float lineHeight=20;
    protected int lineCount;
    protected int maxLines=-1;//最大的行数
    
    protected String mText;
    protected ArrayList<LineParams> lineList=new ArrayList<LineParams>(0);//行的字符串索引
	
    
    protected Paint mPaint = new Paint();  
	{
		mPaint.setTextSize(textSize);  
        mPaint.setAntiAlias(true); 
	}
	
	public CusTextView(Context context) {
		super(context);
	}

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

	publi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值