转载请注明出处
作者:AboutJoke ( http://blog.youkuaiyun.com/u013200308 )
原文链接:http://blog.youkuaiyun.com/u013200308/article/details/57123100
现在各大视屏网站都有了弹幕功能,但显示效果最好的非b站莫属了。如果你也想拥有和b站一样炫酷的弹幕效果,那么就跟着我来一步步实现。
首先放上地址
使用也很简单
repositories {
jcenter()
}
dependencies {
compile 'com.github.ctiao:DanmakuFlameMaster:0.6.4'
compile 'com.github.ctiao:ndkbitmap-armv7a:0.6.4'
# Other ABIs: optional
compile 'com.github.ctiao:ndkbitmap-armv5:0.6.4'
compile 'com.github.ctiao:ndkbitmap-x86:0.6.4'
}
到这里我们就将库导入了as了,接下来就是真正的使用。
<master.flame.danmaku.ui.widget.DanmakuView
android:id="@+id/danmaku_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
用来承载弹幕显示的布局,有了布局就可以去实现代码了,一些方法我也都标上了注释。
//初始化弹幕层
public void initDanmaku() {
mDanmakuContext = DanmakuContext.create();
HashMap<Integer, Integer> maxLine = new HashMap<>();
maxLine.put(BaseDanmaku.TYPE_SCROLL_RL,