前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >里程表式跑马灯自定义控件

里程表式跑马灯自定义控件

作者头像
坑吭吭
发布2018-08-31 17:35:53
4990
发布2018-08-31 17:35:53
举报

效果图

20180628.gif

优点:

  • 内容item复用,节约内存
  • 基于ViewGroup,比较轻量
  • 支持recyclerview中使用
  • item布局支持自定义
  • 极端需求(支持嵌套)

缺点:

  • item的布局只能唯一
  • 不能手动开始和结束动画(不是不可以加,只是本人觉得没必要。。)

源码:

https://github.com/nelson1110/MarqueeView

用法:

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

代码语言:javascript
复制
    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

Step 2. Add the dependency

代码语言:javascript
复制
    dependencies {
            implementation 'com.github.nelson1110:MarqueeView:0.1.0-release'
    }

Step 3. 在xml中添加该控件

代码语言:javascript
复制
<com.libs.nelson.marqueeviewlib.MarqueeView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

xml中的一些可用属性

参数名

意义

orientation

动画滚动方向

animator_duration

动画时间

stay_duration

每个item动画结束后停留的时间

reverse_animator

是否反向动画,默认↑或←

Step 4. 给MarqueeView设置Adapter

代码语言:javascript
复制
marqueeView.setAdapter(object : MarqueeView.MarqueeViewAdapter(){
            override fun getItemLayout(): Int {
                return R.layout.layout
            }
            override fun onBindItemView(itemView: View, position: Int) {
              itemView.findViewById<TextView>(R.id.text).text = position.toString()
            }
            override fun getItemCount(): Int {
                return 4
            }
        })

Adapter中各方法的含义:

方法名

意义

getItemLayout

决定滚动的内容的布局,当前版本默认内容布局只有一种

onBindItemView

给当前position的内容布局绑定数据

getItemCount

决定内容item有多少个

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.06.28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 效果图
  • 优点:
  • 缺点:
  • 源码:
  • 用法:
    • Step 1. Add the JitPack repository to your build file
      • Step 2. Add the dependency
        • Step 3. 在xml中添加该控件
          • Step 4. 给MarqueeView设置Adapter
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档