DMView2 Save

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

Project README

DMView2

GitHub release

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

介绍

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

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

测试效果演示

测试Gif展示

方法参照表

xml参数 作用
dm_direction right_leftleft_right
up_downdown_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_spandm_sleep可配合使用,调整弹幕运动速度

添加依赖

build.gradle文件中添加依赖

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

如何使用?

步骤一

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

    <com.xujiaji.dmlib2.widget.DMTextureView
        android:id="@+id/dmView"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        app:dm_direction="right_left"
        app:dm_span="2dp"
        app:dm_v_space="8dp"
        app:dm_h_space="16dp"
        app:dm_span_time="16" />

步骤二

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

barrage.xml
announcement_image_text.xml
barrage_down_up.xml

步骤三

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

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

或者子线程中添加

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

注意:

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

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

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

更新

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.
Open Source Agenda is not affiliated with "DMView2" Project. README Source: xujiaji/DMView2
Stars
95
Open Issues
8
Last Commit
4 years ago
Repository
License

Open Source Agenda Badge

Open Source Agenda Rating