一個Android上的彈幕控件Open Danmaku

彈幕如今很流行,特別是在視頻播放時,安卓上沒有簡單好用的彈幕控件.
這裏提供一個簡單易用的自定義彈幕控件.
項目地址: https://github.com/linsea/OpenDanmaku



使用方法

完整的使用方法請查看項目的Demo. java

1. 在build.gradle文件中加入依賴.

dependencies {
    compile 'com.linsea:opendanmaku:1.0.0@aar'
 }

2. 在佈局文件中加入自定義的彈幕View.
<com.opendanmaku.DanmakuView
        android:id="@+id/danmakuView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        app:start_Y_offset="0.2"
        app:end_Y_offset="0.8"
        app:max_row="4"
        app:max_running_per_row="2"
        app:pick_interval="1000"
        app:show_debug="false" />

3. 在Activity中生成彈幕對象,並加入到播放列表中.
mDanmakuView = (DanmakuView) findViewById(R.id.danmakuView);

// add danmaku items:
mDanmakuView.addItem(list, true);
mDanmakuView.addItem(new DanmakuItem(this, "Hello World", mDanmakuView.getWidth());

//show danmaku and play animation:
mDanmakuView.show();

//hide and pause playing:
mDanmakuView.hide();

//release all playing and waiting items:
mDanmakuView.clear();

DanmakuView的自定義屬性


 * start_Y_offset android

第一條播放航道距離彈幕View上邊緣的偏移量,注意值是百分比量,以彈幕View的高度爲基準,簡而言之就是彈幕View的上邊緣空出多少百分比. git

 * end_Y_offset github

與上一個屬性相似,最後一條播放航道距離彈幕View上邊緣的偏移量,注意值是百分比量,以彈幕View的高度爲基準,主要做用是便於在彈幕View的底部留出必定的空白. app

 * max_row ide

設置最多多少條播放航道. 佈局

 * max_running_per_row gradle

每條航道上最多同時有多少條彈幕運行. ui

 * pick_interval  this

每隔多少毫秒取出一條彈幕來播放.

 * show_debug 

是否顯示航道線及播放幀率,調試時頗有用,主要用於調試.

相關文章
相關標籤/搜索