MarqueeFactory来提供各种样式的跑马灯View,支持自定义跑马灯ItemView

描述:

通过MarqueeFactory来提供各种样式的跑马灯View, 支持自定义跑马灯ItemView

继承自MarqueeFactory,通过泛型指定ItemView类型以及ItemData类型,之后实现generateMarqueeItemView方法,提

供ItemView,并为ItemView设置数据即可。

应用截图:

跑马灯效果

源码解析:

public class NoticeMF extends MarqueeFactory<TextView, String> {
    private LayoutInflater inflater;

    public NoticeMF(Context mContext) {
        super(mContext);
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public TextView generateMarqueeItemView(String data) {
        TextView mView = (TextView) inflater.inflate(R.layout.notice_item, null);
        mView.setText(data);
        return mView;
    }
}

设置列表数据

MarqueeFactory marqueeFactory2 = new NoticeMF(this);
marqueeFactory2.setData(datas);

设置事件监听

marqueeFactory2.setOnItemClickListener(new MarqueeFactory.OnItemClickListener() {
            @Override
            public void onItemClickListener(MarqueeFactory.ViewHolder holder) {
                Toast.makeText(MainActivity.this, holder.data, Toast.LENGTH_SHORT).show();
            }
});

MarqueeView设置Factory

marqueeView.setMarqueeFactory(marqueeFactory);

 

源码下载:https://github.com/gongwen/MarqueeViewDemo

未经允许不得转载:安度博客 » MarqueeFactory来提供各种样式的跑马灯View,支持自定义跑马灯ItemView

赞 (0)
分享到:更多 ()

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址