Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

DMView2

> 编程语言
Open source

轻量级弹幕,三步即可展示弹幕;也可作为公告的动态展示用途

99 stars0 likes1 views
WebsiteGitHub

About

轻量级弹幕,三步即可展示弹幕;也可作为公告的动态展示用途

DMView2

建议下载主分支类库dmlib2导入项目,由于项目目前并不稳定,并伴随经常修改,短时间不会继续发布远程仓库版本

介绍

该项目是为了弃用DMView,因为当时刚刚进入实习用RecyclerView动画实现的,性能很差。后来我离职后又再也没管了,不过有很多朋友又使用了DMView,本着写出来就要负责的态度,于是写了这个续集。

  1. DMView2不是单纯的只有文字的弹幕,可图文一起;
  2. DMView2目前通过两种方式实现,SurfaceView和TextureView。大家在使用的时候可以自行选择;
  3. DMView2只是展示您设置好的View模板,模板可通过写xml布局,并且可以同时添加多种模板;
  4. 如果是视频弹幕的话那么建议用bilibili开源的弹幕更好点;
  5. 本库适合轻量级弹幕,弹幕样式高度自定义(你可以理解为该框架就是个展示传输带,你把要展示的图片扔上去就行了)
  6. 该类库还可以用来展示动态的公告消息

测试效果演示

方法参照表

xml参数 值 作用
dm_direction right_left、left_right
up_down、down_up down_up:弹幕从下往上跑;
up_down:弹幕从上往下跑;
left_right:弹幕从左往右跑;
right_left:弹幕从右往左跑
dm_span dp 刷新一次界面弹幕所移动的跨度
dm_span_time int 每个跨度需要的时间,单位:ms(毫秒)
dm_sleep int 每次刷新需要睡眠多久,单位:ms(毫秒)
dm_v_space dp 弹幕之间的垂直方向间距
dm_h_space dp 弹幕之间的横向间距

注意: dm_span和dm_sleep可配合使用,调整弹幕运动速度

添加依赖

build.gradle文件中添加依赖

implementation 'com.github.xujiaji:dmlib2:0.0.6'

如何使用?

步骤一

在布局xml文件中添加(或使用DMSurfaceView):

xml
    

步骤二

创建弹幕模板布局,可参考

barrage.xml

announcement_image_text.xml

barrage_down_up.xml

等

步骤三

获取DMSurfaceView实例,通过add方法添加弹幕,弹幕为步骤2设置好数据的模板。

java
View view = LayoutInflater.from(this).inflate(R.layout.announcement_text, null);
mDMSurfaceView.getController().add(view);

或者子线程中添加

java
dmSurfaceView.getController().add(new ViewCreator() {
    @Override
    public View build() {
        return LayoutInflater.from(MainActivity.this).inflate(R.layout.barrage_other, null);
    }
});

注意:

最好在Activity或Fragment的onPause周期中调用下暂停,如下:

java
    @Override
    protected void onPause() {
        super.onPause();
        dmSurfaceView.getController().pause();
    }

该代码只展示了DMSurfaceView,查看DMTexutureView使用请参考 TestTextureActivity.java

更新

  • 0.0.6
    • 低分辨率设备无法显示弹幕
    • TextureView销毁时释放surface
  • 0.0.5
    • 修复锁屏打开App弹幕卡死又重新创建
    • 重构内部所有实现逻辑
    • 新增跨度和睡眠时间来控制速度
    • 修改在xml中使用的属性名
    • 修改测试案例,添加公告的测试案例
  • 0.0.4
    • 修复弹幕过长后的不完整

License

   Copyright 2018 XuJiaji

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javabarragedanmudmdmlib

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言