RecyclerView實現(xiàn)的彈幕之中文DOC

簡介

彈幕動畫通過重寫RecyclerView的默認動畫"DefaultItemAnimator"來實現(xiàn),更改默認動畫過后的文件地址在DmItemAnimator,里面的作用我簡單的注釋了一下。

Github地址:https://github.com/xujiaji/DMView
如有使用過程中出現(xiàn)bug歡迎私信!
英語不好,英文文檔有些地方讓人不好理解,也歡迎糾正。

DMView

dmlib類庫可以幫助你只需要簡單的幾步就可以添加展示彈幕,本類庫由RecyclerView為基礎(chǔ)完成,使用Glide加載頭像。

版本

2.0.0

演示

彈幕GIF演示

安裝

將類庫添加到您的項目中,只需要在您的項目buil.gradle文件中的dependency{}中添加如下信息:

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

使用(總共四步哦?。?/h1>

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”默認的布局和行數(shù)
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);//設(shè)置您要設(shè)置的行數(shù)
        DanMu.init(rvBarrage, config);
  • 這是上面的運行結(jié)果,代碼請轉(zhuǎn)到sample項目。


    自定義的布局
  • 備注: 如果您不想要其中一個布局,比如說您不需要名字,那么對應(yīng)設(shè)置成0。

       Config config = new Config( 
       R.layout.item,
        0,
        R.id.tvMsg,
        R.id.imgHead);
③初始化-方法三:設(shè)置彈幕的行數(shù)
        Config config = new Config();
        config.setRowNum(3);
        DanMu.init(rvBarrage, config);
④初始化-方法四:設(shè)置彈幕的展示時間
        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動畫類庫里面拉下來的幾個文件,如今已經(jīng)刪掉?,F(xiàn)在的實現(xiàn)介紹在:本文頂部簡介。
添加了設(shè)置動畫展示時間的功能。
現(xiàn)在可以銷毀動畫。

v1.1.1

進行了大面積的更改。
修改優(yōu)化了添加彈屏的模式,并且可以添加自定義布局。
可以設(shè)置RecyclerView行數(shù),默認為6行。

v1.0.0

第一版本,僅僅實現(xiàn)了發(fā)送彈幕的功能

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.
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容