软件编程
位置:首页>> 软件编程>> Android编程>> Android实现图文垂直跑马灯效果

Android实现图文垂直跑马灯效果

作者:小草_ing  发布时间:2023-09-05 14:19:36 

标签:Android,跑马灯

最近在维护老项目,老项目有一个地方需要修改,就是垂直跑马灯的问题,之前的垂直跑马灯是只有文字跑马灯,新版需要加上。

之前是用的MarqueeView,看了下源代码是只支持文字的,于是我就改了下原作者的源代码。

MarqueeView类之前作者的


// 创建ViewFlipper下的TextView
private TextView createTextView(CharSequence text, int position) {
 TextView tv = new TextView(mContext);
 tv.setGravity(gravity);
 tv.setText(text);
 tv.setTextColor(textColor);
 tv.setTextSize(textSize);
 tv.setSingleLine(singleLine);
 tv.setTag(position);
 return tv;
}

原实现效果:

Android实现图文垂直跑马灯效果

这里是只支持textview,然后我就改了改


 // 创建ViewFlipper下的View
private View createView(int position) {
 Marquee marquee = marquees.get(position);
 View view = LayoutInflater.from(mContext).inflate(R.layout.view_marquee, null);
 ImageView ivMarquee = (ImageView) view.findViewById(R.id.ivMarquee);
 TextView tvMarquee = (TextView) view.findViewById(R.id.tvMarquee);
 tvMarquee.setText(marquee.getTitle());
 if (isImage) {
  ivMarquee.setVisibility(VISIBLE);
  Glide.with(mContext)
    .load(marquee.getImgUrl())
    .placeholder(R.mipmap.ic_launcher)
    .dontAnimate()
    .into(ivMarquee);
 }
 tvMarquee.setTextSize(textSize);
 view.setTag(position);
 return view;
}

改了之后实现效果:

Android实现图文垂直跑马灯效果

就这样简单

源码地址:MyDemo

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com