// 跑马灯
implementation 'com.sunfusheng:marqueeview:1.3.3'
代码块
if (holder instanceof MyViewHolder_MarQuee){
// 跑马灯
List<String> info = new ArrayList<>();
info.add("心中有阳光,脚底有力量!心中有阳光,脚底有力量!心中有阳光,脚底有力量!");
info.add("升级4G大显存!Nvme协议Pcie SSD,速度快人一步");
info.add("购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)");
info.add("全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G");
info.add("京东月饼让爱更圆满京东自营,闪电配送,更多惊喜");
info.add("【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统");
// 开启跑马灯
((MyViewHolder_MarQuee) holder).marqueeView.startWithList(info);
// 在代码里设置动画
((MyViewHolder_MarQuee) holder).marqueeView.startWithList(info, R.anim.anim_bottom_in, R.anim.anim_top_out);
}
layout布局
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/select_animation01"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="3dp"
android:text="京东快报" />
<com.sunfusheng.marqueeview.MarqueeView
android:id="@+id/marquee"
android:layout_width="match_parent"
android:layout_height="28dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
android:layout_weight="1"
app:mvAnimDuration="1000"
app:mvDirection="bottom_to_top"
app:mvInterval="3000"
app:mvSingleLine="true"
app:mvTextColor="@android:color/black"
app:mvTextSize="15sp"></com.sunfusheng.marqueeview.MarqueeView>
</LinearLayout>
</LinearLayout>
shape文件
select_animation01
<?xml version="1.0" encoding="utf-8"?>
<shape
android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="100dp" android:height="30dp"/>
<corners android:radius="15dp"/>
<solid android:color="@color/White"/>
</shape>
select_animation02
<?xml version="1.0" encoding="utf-8"?>
<shape
android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="100dp" android:height="45dp"/>
<corners android:radius="15dp"/>
<solid android:color="#F8F4F5"/>
</shape>