自定义RecyclerView横向完美循环 滑动广告 (文字完整展示)

先上效果图:


device-2019-06-17-133439.gif

gradle使用:

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
        dependencies {
            implementation 'com.github.Johnjson:MarqueeEffect:v1.0.0'
    }

maven使用:

    
        
            jitpack.io
            https://jitpack.io
        
    
    
        com.github.Johnjson
        MarqueeEffect
        v1.0.0
    

项目中:


  

public class MainActivity extends AppCompatActivity implements CallBackItem {

    private MarqueeRecyclerViews marqueeRecyclerViews;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        marqueeRecyclerViews = findViewById(R.id.mRv_View);
        initData();
    }


    private void initData() {
        ArrayList data = new ArrayList();
        String[] str = new String[]{"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1111111", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB222222", "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC33333"};
        for (int i = 0; i < 3; i++) {
            data.add(i, str[I]);
        }
        marqueeRecyclerViews.setData(data, this);
        marqueeRecyclerViews.startAnimation();
    }

    @Override
    protected void onStop() {
        super.onStop();
        stopAnimation();
    }

    private void startAnimation() {
        if (marqueeRecyclerViews != null) {
            marqueeRecyclerViews.startAnimation();
        }
    }

    private void stopAnimation() {
        if (marqueeRecyclerViews != null) {
            marqueeRecyclerViews.stopAnimation();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        startAnimation();
    }

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

    @Override
    public void callBackPosition(int position, Object o) {

        Toast.makeText(this, "点击位置 " + position + " 返回数据 " + (String) o, Toast.LENGTH_LONG).show();
    }

}

项目地址,欢迎star......
参考:无限循环RecyclerView的完美实现方案

你可能感兴趣的:(自定义RecyclerView横向完美循环 滑动广告 (文字完整展示))