添加依赖
implementation 'com.xj.marqueeView:marqueeView:0.1.20'
布局文件
<com.xj.marqueeview.MarqueeView
android:id="@+id/sort_marqueev_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginLeft="@dimen/dp_10"
app:mvGravity="left"
app:mvDirection="top_to_bottom"
app:mvInterval="3000"
app:mvAnimDuration="500"
/>
MarqueeView基本属性
mvAnimDuration 动画执行时间
mvInterval View 翻页时间间隔
mvGravity View 的摆放位置left、center、right
mvDirection 动画滚动方向:bottom_to_top、top_to_bottom、right_to_left、left_to_right
代码
private fun initMarque(){
val marqueeViewListOf = mutableListOf<String>()
marqueeViewListOf.add("商品搜索,共239款好物")
marqueeViewListOf.add("夏日炎炎")
marqueeViewListOf.add("第一波福利还有30秒到达战场")
marqueeViewListOf.add("新用户立领1000元优惠卷")
var sortMarqueeAdapter = SortMarqueeAdapter(context!!, marqueeViewListOf)
mDataBinding.sortMarqueevItem.setAdapter(sortMarqueeAdapter)
}
适配器
class SortMarqueeAdapter(context: Context, datas:List<String>)
:CommonAdapter<String?>(context, R.layout.sort_marquee_item,datas){
override fun convert(viewHolder: ViewHolder?, item: String?, position: Int) {
val view:TextView = viewHolder!!.getView(R.id.tv_simple_text)
view.text = item
}
}