歌词的获取

摘要:
˂? xmlversion=“1.0”encoding=“utf-8”?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000"
    android:orientation="vertical" >

    <Button
        android: 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="play" />

    <com.anjoyo.getlyric.ui.LyricView
        android: 
        android:layout_width="fill_parent"
        android:layout_height="300dip" >
    </com.anjoyo.getlyric.ui.LyricView>

</LinearLayout>

package com.anjoyo.getlyric.ui;

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * 自定义TextView,用于显示歌词
 * 
 * @author anjoyo
 * 
 */
public class LyricView extends TextView {

        private float high;

        private float width;

        private Paint CurrentPaint;

        private Paint NotCurrentPaint;

        private float TextHigh = 25;

        private float TextSize = 15;

        private int Index = 0;

        private List<LyricContent> mSentenceEntities = new ArrayList<LyricContent>();

        public void setSentenceEntities(List<LyricContent> mSentenceEntities) {
                this.mSentenceEntities = mSentenceEntities;
        }

        public LyricView(Context context) {
                super(context);
                init();
                // TODO Auto-generated constructor stub
        }

        public LyricView(Context context, AttributeSet attrs, int defStyle) {
                super(context, attrs, defStyle);
                init();
                // TODO Auto-generated constructor stub
        }

        public LyricView(Context context, AttributeSet attrs) {
                super(context, attrs);
                init();
                // TODO Auto-generated constructor stub
        }

        private void init() {
                setFocusable(true);

                // 高亮部分
                CurrentPaint = new Paint();
                // 去锯齿 
                CurrentPaint.setAntiAlias(true);
                CurrentPaint.setTextAlign(Paint.Align.CENTER);

                // 非高亮部分
                NotCurrentPaint = new Paint();
                NotCurrentPaint.setAntiAlias(true);
                NotCurrentPaint.setTextAlign(Paint.Align.CENTER);

        }

        @Override
        protected void onDraw(Canvas canvas) {
                // TODO Auto-generated method stub
                super.onDraw(canvas);

                if (canvas == null) {
                        return;
                }

                CurrentPaint.setColor(Color.YELLOW);
                NotCurrentPaint.setColor(Color.GREEN);

                CurrentPaint.setTextSize(TextSize);
                CurrentPaint.setTypeface(Typeface.SERIF);

                NotCurrentPaint.setTextSize(TextSize);
                NotCurrentPaint.setTypeface(Typeface.SERIF);

                try {
                        canvas.drawText(mSentenceEntities.get(Index).getLyric(), width / 2,
                                        high / 2, CurrentPaint);

                        float tempY = high / 2;
                        // 画出本句之前的句子
                        for (int i = Index - 1; i >= 0; i--) {

                                // 向上推移
                                tempY = tempY - TextHigh;

                                canvas.drawText(mSentenceEntities.get(i).getLyric(), width / 2,
                                                tempY, NotCurrentPaint);

                        }

                        tempY = high / 2;
                        // 画出本句之后的句子
                        for (int i = Index + 1; i < mSentenceEntities.size(); i++) {
                                // 往下推移
                                tempY = tempY + TextHigh;

                                canvas.drawText(mSentenceEntities.get(i).getLyric(), width / 2,
                                                tempY, NotCurrentPaint);

                        }
                } catch (Exception e) {
                        // TODO: handle exception
                }

        }

        @Override
        protected void onSizeChanged(int w, int h, int oldw, int oldh) {
                // TODO Auto-generated method stub
                super.onSizeChanged(w, h, oldw, oldh);
                this.high = h;
                this.width = w;
        }

        public void SetIndex(int index) {
                this.Index = index;
                // System.out.println(index);
        }

}


免责声明:文章转载自《歌词的获取》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇H5入门基础(一)微信小程序全屏背景图适配下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

vue 优化小技巧 之 require.context()

1、require.context() 回忆一下 当我们引入组件时   第一步 创建一个子组件   第二步 import ... form ...     第三步 components:{..}       第四步 页面使用 <...></...>   代码实现:                                 ...

《Zuul网关》之GETPOSTPUT请求报文重组并支持multipart/form-data

1、重组参数 假设需要重新组装的参数如下: @Setter @Getter public class DecodeParameters implementsSerializable{   private static final long serialVersionUID = -874947393093003083830L;   //通用参数   pr...

SpringBoot启动过程解析(简化)

springBoot web方式启动过程 在这个启动过程中会有各种SpringBoot对外提供的扩展接口来对不同启动阶段进行自定义操作。 了解启动过程也是为了让我们更好理解SpringBoot提供的扩展接口使用   jar包启动或者外置war包启动都是调用SpringApplication.run()方法进行项目启动 tomcat会查询context上下文...

彻底搞懂Spring类加载(注解方式)

单例预加载默认 单例懒加载   正确的加载时机   错误的加载时机 多例懒加载仅支持懒加载 spring beanfactory类高级用法   反射方式加载类 需要注意的问题 通过 Spring 注册的类一共只有三种加载方式! 环境:spring-context 4.2.6jdk 8Eclipse 4.7 最简单的配置 <?xml ve...

5个Android开发中比较常见的内存泄漏问题及解决办法

在Android开发中,内存泄漏是比较常见的问题,有过一些Android编程经历的童鞋应该都遇到过,但为什么会出现内存泄漏呢?内存泄漏又有什么影响呢? 在Android程序开发中,当一个对象已经不需要再使用了,本该被回收时,而另外一个正在使用的对象持有它的引用从而导致它不能被回收,这就导致本该被回收的对象不能被回收而停留在堆内存中,内存泄漏就产生了。 内存...

HttpClient4.3教程 第四章 HTTP认证

HttpClient4.3教程 第四章 HTTP认证 Posted on2013 年 10 月 17 日 HttpClient既支持HTTP标准规范定义的认证模式,又支持一些广泛使用的非标准认证模式,比如NTLM和SPNEGO。 4.1.用户凭证 任何用户认证的过程,都需要一系列的凭证来确定用户的身份。最简单的用户凭证可以是用户名和密码这种形式。Use...