1_創建歌詞顯示類LyricShow:文字大小、抗鋸齒、居中對齊
public class LyricShow extends TextView { private ArrayList<Lyric> lyrics; /** * 畫筆 */ private Paint currentPaint; private Paint noCurrentPaint; //在布局文件中實例化的時候回調這個方法 public LyricShow(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub initView(); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { // TODO Auto-generated method stub super.onSizeChanged(w, h, oldw, oldh); width = w; height = h; } private void initView() { currentPaint = new Paint(); //設置抗鋸齒 currentPaint.setAntiAlias(true); //設置顏色 currentPaint.setColor(Color.GREEN); //設置文字大小 currentPaint.setTextSize(16); //設置對齊 currentPaint.setTextAlign(Paint.Align.CENTER); noCurrentPaint = new Paint(); //設置抗鋸齒 noCurrentPaint.setAntiAlias(true); //設置顏色 noCurrentPaint.setColor(Color.WHITE); //設置文字大小 noCurrentPaint.setTextSize(16); //設置對齊 noCurrentPaint.setTextAlign(Paint.Align.CENTER); } @Override protected void onDraw(Canvas canvas) { // super.onDraw(canvas); canvas.drawText("沒有找到歌詞", width/2, height/2, currentPaint); } }
2_畫出歌詞-當前句-前句-後句