logo
当前位置:首 页 > 移动开发 >android > 查看文章

一个帮您快速实现跑马灯效果的library

android, 移动开发 你是第3146个围观者 0条评论 供稿者: 标签:

一个帮您快速实现跑马灯效果的library

使用

Gradle:

compile ‘com.gongwen:marqueelibrary:1.0.4’

通过自定义MarqueeFactory来设置ItemView

继承自MarqueeFactory,通过泛型指定ItemView类型以及ItemData类型,之后实现generateMarqueeItemView方法,提供ItemView,并为ItemView设置数据即可。

例如:

public class NoticeMF extends MarqueeFactory {    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 marqueeFactory = new NoticeMF(this);marqueeFactory.setData(datas);

适用于多次设置数据源

MarqueeFactory marqueeFactory = new NoticeMF(this);marqueeFactory.resetData(datas);

设置事件监听

marqueeFactory.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);

重影问题可参考以下解决方案(参考自这里)

@Overridepublic void onStart() {    super.onStart();    marqueeView.startFlipping();}@Overridepublic void onStop() {    super.onStop();    marqueeView.stopFlipping();}

License

Copyright (C) 2016 1798550470@qq.comLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

  •  
说说梦想,谈谈感悟 ,聊聊技术,有啥要说的来github留言吧 https://github.com/cjx2328

—— 陈 建鑫

陈建鑫
你可能也喜欢Related Posts
footer logo
未经许可请勿自行使用、转载、修改、复制、发行、出售、发表或以其它方式利用本网站之内容。站长联系:cjx2328#126.com(修改#为@)
Copyright ©ziao Studio All Rights Reserved. E-mail:cjx2328#126.com(#号改成@) 沪ICP备14052271号-3