MarqueeView.java 文件源码

java
阅读 35 收藏 0 点赞 0 评论 0

项目:GitHub 作者:
/**
 * 根据字符串和宽度,启动翻页公告
 *
 * @param notice 字符串
 */
private void startWithFixedWidth(String notice, @AnimRes int inAnimResId, @AnimRes int outAnimResID) {
    int noticeLength = notice.length();
    int width = Utils.px2dip(getContext(), getWidth());
    if (width == 0) {
        throw new RuntimeException("Please set the width of MarqueeView !");
    }
    int limit = width / textSize;
    List list = new ArrayList();

    if (noticeLength <= limit) {
        list.add(notice);
    } else {
        int size = noticeLength / limit + (noticeLength % limit != 0 ? 1 : 0);
        for (int i = 0; i < size; i++) {
            int startIndex = i * limit;
            int endIndex = ((i + 1) * limit >= noticeLength ? noticeLength : (i + 1) * limit);
            list.add(notice.substring(startIndex, endIndex));
        }
    }

    if (notices == null) notices = new ArrayList<>();
    notices.clear();
    notices.addAll(list);
    start(inAnimResId, outAnimResID);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号