• Stars
    star
    408
  • Rank 101,976 (Top 3 %)
  • Language
    Java
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

一种支持多种弹幕样式的弹幕视图控件

XDanmuku V1.1版本

license

更新内容 V1.1

  1. 移动View线程数修改为1
  2. 加入View缓存,并能自动调整缓存空间大小
  3. 修改Entity绑定View的方式

使用方法

XDanmuku

一种支持多种弹幕样式的弹幕视图控件(点击可以查看添加库的方法)。

本项目是一个开源的弹幕控件库,能够支持多种样式弹幕,弹幕点击监听,弹幕分区域显示,自定义移动速度等功能,项目原理是通过自定义ViewGroup。可能是目前轻量级弹幕库中功能最强大的一款了。

效果

  • 常规样式

  • 点击事件

  • 多种弹幕样式

  • 分区域显示

  • GIF效果图

使用

0. 添加依赖

1. 导入xdanmuku源码

你可以直接下载本项目xdanmuku模块,并导入项目目录,并添加依赖compile project(':xdanmuku')

2. Gradle

先把jitpack仓库添加到项目根 build.gradle(Project)文件中,

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

然后在你的项目中添加依赖

dependencies {
        compile 'com.github.hust201010701:XDanmuku:-SNAPSHOT'
}

其他添加依赖的方式,如maven等请自行到点我查看。

1. 添加控件

在布局xml中添加控件

<com.orzangleli.xdanmuku.DanmuContainerView
    android:id="@+id/danmuContainerView"
    android:layout_width="match_parent"
    android:layout_height="240dp"
    />

2. 添加自定义弹幕Entity(需要继承自Model)

类似于DanmuEntity.java

3. 继承XAdapter

类似于ListView的BaseAdapter的结构,具体参照 DanmuAdapter.java

4. 添加弹幕

DanmuEntity danmuEntity = new DanmuEntity();
danmuEntity.setContent(SEED[random.nextInt(5)]);
danmuEntity.setType(0);
danmuEntity.setTime("23:20:11");
danmuContainerView.addDanmu(danmuEntity);

5. 弹幕点击事件监听

//弹幕点击事件
danmuContainerView.setOnItemClickListener(new DanmuContainerView.OnItemClickListener() {
    @Override
    public void onItemClick(Model model) {
        DanmuEntity danmuEntity = (DanmuEntity) model;
        Toast.makeText(MainActivity.this, danmuEntity.content, Toast.LENGTH_SHORT).show();
    }
});

6. 设置弹幕移动速度

DanmuContainerView中预设了三种弹幕移动速度:

public final static int LOW_SPEED = 1;
public final static int NORMAL_SPEED = 4;
public final static int HIGH_SPEED = 8;

设置速度通过setSpeed方法:

danmuContainerView.setSpeed(DanmuContainerView.HIGH_SPEED);

同时你可以传递具体的int型速度(建议速度值在1-8之间,数值越大速度越快):

danmuContainerView.setSpeed(5);

7. 弹幕显示区域

本人将弹幕控件按照竖向均分为3份,分别为GRAVITY_TOP,GRAVITY_CENTER,GRAVITY_BOTTOM。用户可以自由组合显示区域,默认情况下全区域(GRAVITY_FULL)显示。设置要显示的区域通过setGravity方法实现,参数可以使用 | 进行连接。

//只在上方和中间区域显示弹幕
danmuContainerView.setGravity(DanmuContainerView.GRAVITY_TOP | DanmuContainerView.GRAVITY_CENTER);

致谢

感谢以下用户的建议和反馈:

附录

有几篇开发本库时的记录和心得,欢迎大家阅读点赞:

MIT License

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.

More Repositories

1

CheckResourceConflict

Android 自动检测资源冲突的gradle 插件(An Android Gradle Plugin For Checking Conflict Resources)
Groovy
231
star
2

XRadarView

A highly customizable radar view for Android
Java
105
star
3

CouponView

android 卡券布局 可以自定义横向/竖向的锯齿
Java
24
star
4

RetrofitMultiFilesUploadClient

Android 用Retrofit 2实现多文件上传实战 Android端
Java
18
star
5

KeyboardPanelSwitchDemo

android keyboard键盘和panel面板切换时,屏幕闪烁解决方案
Java
10
star
6

RoateIndicatorViewDemo

🚌高仿转转APP首页banner的指示器控件
Java
10
star
7

Anivia

一个热修复框架
Groovy
10
star
8

TaonvlangCrawler

TaonvlangCrawler Python3 实现淘女郎照片爬虫
Python
9
star
9

MultiFileUploadServer

Android 用Retrofit 2实现多文件上传实战 Server端
Python
6
star
10

QiniuImageUploader

写博客时候经常需要贴图,本项目使用Python 实现图形化上传界面,自动生成markdown 图片标签,支持批量上传
Python
6
star
11

XPlaceHolder

🔥 An elegant and highly expandable android library for displaying different state of app like loading, empty, error and successful state.
Java
4
star
12

Danmu

自定义弹幕视图,可以实现水平/竖直方向,正向/反向弹幕,可以自定义颜色、文字大小等
Java
3
star
13

online-subsampling-scale-image-view

An android library that can view an online and local big picture, based on [subsampling-scale-image-view](https://github.com/davemorrissey/subsampling-scale-image-view)
Java
2
star
14

Arduino_W5100_Yeelink_Temperature

Arduino_W5100_Yeelink_Tempertrue
Arduino
1
star
15

AndroidBlogDemo

公众号 Android开发实验室 文章附属Demo
Java
1
star
16

WpBlogToMarkdownFile

将wp中的文章转化为md格式的文件,生成的md文件可以直接迁移到hexo框架中
Python
1
star
17

OneKeyUploadImage

OneKeyUploadImage is a project to help you upload image saved in clipboard by srceenshot software with onekey.可以帮助你一键上传截屏软件保存在剪切板中的图片。
Python
1
star
18

SnackbarCustomUsage

SnackbarCustomUsage is a project which have highly custom snackbar usage:show snackbar on the top of the mobile, custom the color of message text and the background, and add a view to snackbar.
Java
1
star