Ò»°ã¸è´ÊÎļþµÄ¸ñʽ´ó¸ÅÈçÏÂ:
[ar:ÒÕÈËÃû]
[ti:ÇúÃû]
[al:ר¼Ãû]
[by:±àÕߣ¨Ö¸±à¼LRC¸è´ÊµÄÈË£©]
[offset:ʱ¼ä²¹³¥Öµ] Æäµ¥Î»ÊǺÁÃ룬ÕýÖµ±íʾÕûÌåÌáǰ£¬¸ºÖµÏà·´¡£ÕâÊÇÓÃÓÚ×ÜÌåµ÷ÕûÏÔʾ¿ìÂýµÄ¡£
µ«Ò²²»Ò»¶¨£¬ÓÐʱºò²¢Ã»ÓÐÇ°ÃæÄÇЩar:µÈ±êʶ·û£¬ËùÒÔÎÒÃÇÕâÀïÒ²ÌṩÁËÁíÒ»ÖÖ½âÎö·½Ê½¡£
¸è´ÊÎļþÖеÄʱ¼ä¸ñʽÔò±È½Ïͳһ:[00:00.50]µÈµÈ£¬00:±íʾ·ÖÖÓ£¬00.±íʾÃëÊý£¬.50±íʾºÁÃëÊý£¬µ±È»£¬ÎÒÃÇ×îºóÊÇÒª½«ËüÃÇת»¯ÎªºÁÃëÊý´¦Àí²Å±È½Ï·½±ã¡£
´¦ÀíÍê¸è´ÊÎļþ²¢µÃµ½ÎÒÃÇÏëÒªµÄÊý¾Ýºó£¬ÎÒÃǾÍÒª¿¼ÂÇÈçºÎÔÚÊÖ»úÉϹö¶¯ÏÔʾÎÒÃǵĸè´Ê²¢ÇÒÓëÎÒÃǵõ½µÄʱ¼äͬ²½ÁË¡£
ÏÈÊDz¼¾ÖÎļþ:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:id="@+id/button"
android:layout_width="60dip"
android:layout_height="60dip"
android:text="@string/Í£Ö¹" />
<com.example.slidechange.WordView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/button" />
WordViewÊÇ×Ô¶¨ÒåµÄTextView£¬Ëü¼Ì³Ð×ÔTextView£º
public class WordView extends TextView {
private List mWordsList = new ArrayList();
private Paint mLoseFocusPaint;
private Paint mOnFocusePaint;
private float mX = 0;
private float mMiddleY = 0;
private float mY = 0;
private static final int DY = 50;
private int mIndex = 0;
public WordView(Context context) throws IOException {
super(context);
init();
}
public WordView(Context context, AttributeSet attrs) throws IOException {
super(context, attrs);
init();
}
public WordView(Context context, AttributeSet attrs, int defStyle)
throws IOException {
super(context, attrs, defStyle);
init();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.BLACK);
Paint p = mLoseFocusPaint;
p.setTextAlign(Paint.Align.CENTER);
Paint p2 = mOnFocusePaint;
p2.setTextAlign(Paint.Align.CENTER);
canvas.drawText(mWordsList.get(mIndex), mX, mMiddleY, p2);
int alphaValue = 25;
float tempY = mMiddleY;
for (int i = mIndex - 1; i >= 0; i--) {
tempY -= DY;
if (tempY < 0) {
break;
}
p.setColor(Color.argb(255 - alphaValue, 245, 245, 245));
canvas.drawText(mWordsList.get(i), mX, tempY, p);
alphaValue += 25;
}
alphaValue = 25;
tempY = mMiddleY;
for (int i = mIndex + 1, len = mWordsList.size(); i < len; i++) {
tempY += DY;
if (tempY > mY) {
break;
}
p.setColor(Color.argb(255 - alphaValue, 245, 245, 245));
canvas.drawText(mWordsList.get(i), mX, tempY, p);
alphaValue += 25;
}
mIndex++;
}
@Override
protected void onSizeChanged(int w, int h, int ow, int oh) {
super.onSizeChanged(w, h, ow, oh);
mX = w * 0.5f;
mY = h;
mMiddleY = h * 0.3f;
}
@SuppressLint("SdCardPath")
private void init() throws IOException {
setFocusable(true);
LrcHandle lrcHandler = new LrcHandle();
lrcHandler.readLRC("/sdcard/ÅãÎÒÈ¥Á÷ÀË.lrc");
mWordsList = lrcHandler.getWords();
mLoseFocusPaint = new Paint();
mLoseFocusPaint.setAntiAlias(true);
mLoseFocusPaint.setTextSize(22);
mLoseFocusPaint.setColor(Color.WHITE);
mLoseFocusPaint.setTypeface(Typeface.SERIF);
mOnFocusePaint = new Paint();
mOnFocusePaint.setAntiAlias(true);
mOnFocusePaint.setColor(Color.YELLOW);
mOnFocusePaint.setTextSize(30);
mOnFocusePaint.setTypeface(Typeface.SANS_SERIF);
}
}
×îÖ÷ÒªµÄÊǸ²¸ÇTextViewµÄonDraw()ºÍonSizeChanged()¡£ |