三方MD控件Android开发探索

RecyclerView实现的弹幕之中文DOC

2016-08-10  本文已影响1727人  灵魂奏响曲

简介

弹幕动画通过重写RecyclerView的默认动画"DefaultItemAnimator"来实现,更改默认动画过后的文件地址在DmItemAnimator,里面的作用我简单的注释了一下。

Github地址:https://github.com/xujiaji/DMView
如有使用过程中出现bug欢迎私信!
英语不好,英文文档有些地方让人不好理解,也欢迎纠正。

DMView

dmlib类库可以帮助你只需要简单的几步就可以添加展示弹幕,本类库由RecyclerView为基础完成,使用Glide加载头像。

版本

2.0.0

演示

弹幕GIF演示

安装

将类库添加到您的项目中,只需要在您的项目buil.gradle文件中的dependency{}中添加如下信息:

dependencies {compile 'com.github.xujiaji:dmlib:1.1.1'}

使用(总共四步哦!)

1. 需要在布局中添加RecyclerView(因为以RecyclerView为主体)

<android.support.v7.widget.RecyclerView        
  android:id="@+id/rvBarrage"       
  android:layout_width="match_parent"        
  android:layout_height="match_parent"        
  android:layout_marginTop="90dp"        
  android:layout_marginBottom="90dp"        
  android:overScrollMode="never" />

2.初始化 "DanMu" 在获取了RecyclerView之后

①初始化-方法一 : 使用“dmlib”默认的布局和行数
rvBarrage = (RecyclerView) findViewById(R.id.rvBarrage);
DanMu.init(rvBarrage);
②初始化-方法二: 配置您想要的布局
Config config = new Config(
        R.layout.item,
        R.id.tvName,
        R.id.tvMsg,
        R.id.imgHead);
        config.setRowNum(5);//设置您要设置的行数
        DanMu.init(rvBarrage, config);
       Config config = new Config( 
       R.layout.item,
        0,
        R.id.tvMsg,
        R.id.imgHead);
③初始化-方法三:设置弹幕的行数
        Config config = new Config();
        config.setRowNum(3);
        DanMu.init(rvBarrage, config);
④初始化-方法四:设置弹幕的展示时间
        Config config = new Config();
        config.setDuration(10000);
        DanMu.init(rvBarrage, config);

3.添加一个弹幕

DanMu.call()        
       .picUrl("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=150237755,4294706681&fm=116&gp=0.jpg") 
       .name("xujiaji") 
       .msg("Bullet screen massage show ...")
       .show();

No.1

DanMu.call()        
        .picUrl("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=150237755,4294706681&fm=116&gp=0.jpg")
        .msg("Bullet screen massage show ...")
        .show();
头像和消息

No.2

DanMu.call()
        .msg("Bullet screen massage show ...")
        .show();
只有消息.png

No.3

javaDanMu.call()
        .name("xujiaji")
        .msg("Bullet screen massage show ...")
        .show();
名字和消息.png

No.4

DanMu.call()        
        .picUrl("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=150237755,4294706681&fm=116&gp=0.jpg")
        .show();
只有头像

3. 销毁弹幕

    @Override
    protected void onDestroy() {
        DanMu.destroy();
        super.onDestroy();
    }

Activity中所有的代码

public class MainActivity extends AppCompatActivity {
    private RecyclerView rvBarrage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rvBarrage = (RecyclerView) findViewById(R.id.rvBarrage);
        //sample.1: default init
        DanMu.init(rvBarrage);

        //sample.2: config yourself layout
//        Config config = new Config(
//                R.layout.item,
//                R.id.tvName,
//                R.id.tvMsg,
//                R.id.imgHead);
//        config.setRowNum(5);  // setting bullet screen's rows
//        DanMu.init(rvBarrage, config);

        //sample.3: setting bullet screen's rows
//        Config config = new Config();
//        config.setRowNum(3);
//        DanMu.init(rvBarrage, config);

        //sample.4 setting bullet screen's animator duration
//        Config config = new Config();
//        config.setDuration(10000);
//        DanMu.init(rvBarrage, config);
    }

    public void onAddClick(View view) {
        DanMu.call()
                .picUrl("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=150237755,4294706681&fm=116&gp=0.jpg")
                .name("xujiaji")
                .msg("Bullet screen massage show ...")
                .show();
    }

    @Override
    protected void onDestroy() {
        DanMu.destroy();
        super.onDestroy();
    }
}

“dmlib”更新日志

v2.0.0

更改了动画库,原先是从github上面的一个RecyclerView动画类库里面拉下来的几个文件,如今已经删掉。现在的实现介绍在:本文顶部简介。
添加了设置动画展示时间的功能。
现在可以销毁动画。

v1.1.1

进行了大面积的更改。
修改优化了添加弹屏的模式,并且可以添加自定义布局。
可以设置RecyclerView行数,默认为6行。

v1.0.0

第一版本,仅仅实现了发送弹幕的功能

License

Copyright 2016 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.
上一篇 下一篇

猜你喜欢

热点阅读