源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-05-26 06:12 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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;
 }
原实现效果: [img]http://files.jb51.net/file_images/article/201708/2017080309545165.gif[/img] 这里是只支持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;
 }

改了之后实现效果: [img]http://files.jb51.net/file_images/article/201708/2017080309545366.gif[/img] 就这样简单 源码地址:[url=https://github.com/DBxiaocao/MyDemo]MyDemo[/url] 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部