博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
最多显示6行并且最多显示三条文本
阅读量:6503 次
发布时间:2019-06-24

本文共 5495 字,大约阅读时间需要 18 分钟。

  hot3.png

        private void setCommentContent(ViewHolder vh, String feedId, int commentNum, ArrayList
 comment_lists)        {            if(commentNum <= 0 || comment_lists == null || comment_lists.isEmpty())            {                for(int i = 0; i < vh.tvCommentTexts.size(); i++)                {                    View view = vh.tvCommentTexts.get(i);                    view.setVisibility(View.GONE);                }                vh.llCommentContent.setVisibility(View.GONE);                vh.tvCommentOtherLine.setVisibility(View.GONE);                vh.tvCommentOther.setVisibility(View.GONE);            }            else            {                vh.llCommentContent.setVisibility(View.VISIBLE);                int realNum = Math.min(commentNum, comment_lists.size());                int count = Math.min(vh.tvCommentTexts.size(), realNum);//                float width = 0;//                int commentLine = 0;//                for(int j = 0; j < count; j++)//                {//                    CommentItem comment = comment_lists.get(j);//                    width = measureTextWidth(vh.tvCommentTexts.get(0), comment.getContent());//                    int tLine = commentLine + (int)(width / mCommentWidth);//                    if(width % mCommentWidth > 0) tLine = tLine + 1;//                    if(tLine > 4)//                    {//                        count = j + 1;//                        break;//                    }//                    commentLine = tLine;//                }                float width = 0;                int commentLine = 0;                int i = 0;                for(; i < count; i++)                {                    TextView view = vh.tvCommentTexts.get(i);                    view.setVisibility(View.VISIBLE);                    CommentItem comment = comment_lists.get(i);                    CharSequence commentContent = formatCommentContent(comment);                    view.setText(commentContent);                    width = measureTextWidth(view, commentContent.toString());                    int tLine = commentLine + (int)(width / mCommentWidth);                    if(width % mCommentWidth > 0) tLine = tLine + 1;                    if(tLine >= 6 && (6 - commentLine > 0))                    {//                        view.setVisibility(View.GONE);                        view.setMaxLines(6 - commentLine);                        i++;                        break;                    }                    else                    {                        view.setMaxLines(6);                    }                    commentLine = tLine;                }                if(i < commentNum)                {                    int leftCount = commentNum - i;                    vh.tvCommentOtherLine.setVisibility(View.VISIBLE);                    vh.tvCommentOther.setVisibility(View.VISIBLE);                    vh.tvCommentOther.setText(mResources.getString(R.string.bbs_comment_other, leftCount));                    vh.tvCommentOther.setOnClickListener(new DynamicDetailClickListener(feedId, false));                }                else                {                    vh.tvCommentOtherLine.setVisibility(View.GONE);                    vh.tvCommentOther.setVisibility(View.GONE);                }                for(; i < vh.tvCommentTexts.size(); i++)                {                    View view = vh.tvCommentTexts.get(i);                    view.setVisibility(View.GONE);                }            }        }        private CharSequence formatCommentContent(CommentItem comment)        {            String nick = comment.getNick();            String replayNick = comment.getReply_nick();            if(mMyUid.equals(String.valueOf(comment.getUid())))            {                nick = getMyNick(nick);            }            if(mMyUid.equals(String.valueOf(comment.getReply_uid())))            {                replayNick = getMyNick(replayNick);            }            int color = (comment.getType() == 1 || comment.getType() == 2) ? redColor : blueColor;            int replyColor = (comment.getReply_type() == 1 || comment.getReply_type() == 2) ? redColor : blueColor;            SpannableStringBuilder spanText = null;            if(TextUtils.isEmpty(replayNick))            {                String prefix = nick + MAOHAO;                spanText = new SpannableStringBuilder(prefix + comment.getContent());                spanText.setSpan(new ForegroundColorSpan(color), 0, prefix.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);            }            else            {                String prefix1 = nick + HUIFU;                String prefix2 = prefix1 + replayNick+ MAOHAO;                spanText = new SpannableStringBuilder(prefix2 + comment.getContent());                spanText.setSpan(new ForegroundColorSpan(color), 0, nick.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);                spanText.setSpan(new ForegroundColorSpan(replyColor), prefix1.length(), prefix2.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);            }            return spanText;        }        private float measureTextWidth(TextView textView, String content)        {            Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);            mTextPaint.setColor(textView.getCurrentTextColor());            mTextPaint.setTextSize(textView.getTextSize());            float textWidth = mTextPaint.measureText(content);            return textWidth;        }

转载于:https://my.oschina.net/bruces/blog/597354

你可能感兴趣的文章
iphone UIView的一些基本方法理解
查看>>
sys.check_constraints
查看>>
vue问题
查看>>
Linux常用命令大全
查看>>
ThinkPHP 框架学习
查看>>
yii1框架,事务使用方法
查看>>
css3箭头效果
查看>>
Python学习笔记【第一篇】:认识python和基础知识
查看>>
MathType在手,公式不求人!
查看>>
测试用例设计
查看>>
三层架构
查看>>
Python变量类型(l整型,长整形,浮点型,复数,列表,元组,字典)学习
查看>>
解决方案(.sln)文件
查看>>
理解cookie和session机制
查看>>
【Treap】bzoj1588-HNOI2002营业额统计
查看>>
第六周作业
查看>>
利用ZYNQ SOC快速打开算法验证通路(5)——system generator算法IP导入IP integrator
查看>>
指针和引用的区别
查看>>
运行PHP出现No input file specified错误解决办法
查看>>
【重建】从FJOI2016一试谈起
查看>>