一种支持多种弹幕样式的弹幕视图控件
本项目是一个开源的弹幕控件库,能够支持多种样式弹幕,弹幕点击监听,弹幕分区域显示,自定义移动速度等功能,项目原理是通过自定义ComponentContainer。可能是目前轻量级弹幕库中功能最强大的一款了。
...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
testImplementation 'junit:junit:4.13'
ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100'
compile project(path: ':xdanmuku')
implementation 'io.openharmony.tpc.thirdlib:glide:1.0.6'
}
...
2.maven引用
...
allprojects {
repositories {
mavenCentral()
}
}
...
dependencies {
...
implementation 'com.gitee.archermind-ti:XDanmuku:1.0.0'
...
}
<com.orzangleli.xdanmuku.DanmuContainerView
ohos:id="$+id:danmuContainerView"
ohos:width="match_parent"
ohos:height="240vp"
/>
添加自定义弹幕Entity(需要继承自Model) 类似于DanmuEntity.java
继承XAdapter 类似于ListContainer的BaseItemProvider的结构,具体参照DanmuAdapter.java
添加弹幕
DanmuEntity danmuEntity = new DanmuEntity();
danmuEntity.setContent("弹幕"+i);
danmuEntity.setType(0);
danmuEntity.setTime("23:20:11");
danmuEntity.setShowTime((long) (VIDEO_DURATION * random.nextFloat()));
danmuEntities.add(danmuEntity);
//弹幕点击事件
danmuContainerView.setOnItemClickListener(new DanmuContainerView.OnItemClickListener() {
@Override
public void onItemClick(Model model) {
DanmuEntity danmuEntity = (DanmuEntity) model;
//弹框提示会造成卡顿
new ToastDialog(MainAbility.this).setContentText( danmuEntity.content).show();
}
});
DanmuContainerView中预设了三种弹幕移动速度:
public final static int LOW_SPEED = 10*1000;
public final static int NORMAL_SPEED = 4*1000;
public final static int HIGH_SPEED = 1000;
设置速度通过setSpeed方法:
danmuContainerView.setSpeed(DanmuContainerView.HIGH_SPEED);
//只在上方和中间区域显示弹幕
danmuContainerView.setGravity(DanmuContainerView.GRAVITY_TOP | DanmuContainerView.GRAVITY_CENTER);
1.完成基础功能,弹幕显示。
Copyright (c) 2017 orzangleli
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。