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

时间:2022-07-27
本文章向大家介绍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;
 }

原实现效果:

这里是只支持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;
 }

改了之后实现效果:

就这样简单

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