1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關咨詢
      選擇下列產品馬上在線溝通
      服務時間:8:30-17:00
      你可能遇到了下面的問題
      關閉右側工具欄

      新聞中心

      這里有您想知道的互聯網營銷解決方案
      Android實現朋友圈評論回復列表

      本文實例為大家分享了Android實現朋友圈評論回復列表的具體代碼,供大家參考,具體內容如下

      成都創(chuàng)新互聯公司服務項目包括大洼網站建設、大洼網站制作、大洼網頁制作以及大洼網絡營銷策劃等。多年來,我們專注于互聯網行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構等提供互聯網行業(yè)的解決方案,大洼網站推廣取得了明顯的社會效益與經濟效益。目前,我們服務的客戶以成都為中心已經輻射到大洼省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!

      Android實現朋友圈評論回復列表

      Android實現朋友圈點贊列表

      Android實現朋友圈多圖顯示功能

      正文

      還是老流程,先來看一下效果圖:

      Android實現朋友圈評論回復列表

      然后是主要實現代碼:

      CommentsView

      public class CommentsView extends LinearLayout {
      
       private Context mContext;
       private List mDatas;
       private onItemClickListener listener;
      
       public CommentsView(Context context) {
        this(context, null);
       }
      
       public CommentsView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
       }
      
       public CommentsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setOrientation(VERTICAL);
        this.mContext = context;
       }
      
       /**
        * 設置評論列表信息
        *
        * @param list
        */
       public void setList(List list) {
        mDatas = list;
       }
      
       public void setOnItemClickListener(onItemClickListener listener) {
        this.listener = listener;
       }
      
       public void notifyDataSetChanged() {
        removeAllViews();
        if (mDatas == null || mDatas.size() <= 0) {
         return;
        }
        LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(0, 10, 0, 10);
        for (int i = 0; i < mDatas.size(); i++) {
         View view = getView(i);
         if (view == null) {
          throw new NullPointerException("listview item layout is null, please check getView()...");
         }
         addView(view, i, layoutParams);
        }
       }
      
       private View getView(final int position) {
        final CommentsBean item = mDatas.get(position);
        UserBean replyUser = item.getReplyUser();
        boolean hasReply = false; // 是否有回復
        if (replyUser != null) {
         hasReply = true;
        }
        TextView textView = new TextView(mContext);
        textView.setTextSize(15);
        textView.setTextColor(0xff686868);
      
        SpannableStringBuilder builder = new SpannableStringBuilder();
        UserBean comUser = item.getCommentsUser();
        String name = comUser.getUserName();
        if (hasReply) {
         builder.append(setClickableSpan(name, item.getCommentsUser()));
         builder.append(" 回復 ");
         builder.append(setClickableSpan(replyUser.getUserName(), item.getReplyUser()));
      
        } else {
         builder.append(setClickableSpan(name, item.getCommentsUser()));
        }
        builder.append(" : ");
        builder.append(setClickableSpanContent(item.getContent(), position));
        textView.setText(builder);
        // 設置點擊背景色
        textView.setHighlightColor(getResources().getColor(android.R.color.transparent));
      //  textView.setHighlightColor(0xff000000);
      
        textView.setMovementMethod(new CircleMovementMethod(0xffcccccc, 0xffcccccc));
      
        textView.setOnClickListener(new OnClickListener() {
         @Override
         public void onClick(View v) {
          if (listener != null) {
           listener.onItemClick(position, item);
          }
         }
        });
      
        return textView;
       }
      
       /**
        * 設置評論內容點擊事件
        *
        * @param item
        * @param position
        * @return
        */
       public SpannableString setClickableSpanContent(final String item, final int position) {
        final SpannableString string = new SpannableString(item);
        ClickableSpan span = new ClickableSpan() {
         @Override
         public void onClick(View widget) {
          // TODO: 2017/9/3 評論內容點擊事件
          Toast.makeText(mContext, "position: " + position + " , content: " + item, Toast.LENGTH_SHORT).show();
         }
      
         @Override
         public void updateDrawState(TextPaint ds) {
          super.updateDrawState(ds);
          // 設置顯示的內容文本顏色
          ds.setColor(0xff686868);
          ds.setUnderlineText(false);
         }
        };
        string.setSpan(span, 0, string.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return string;
       }
      
       /**
        * 設置評論用戶名字點擊事件
        *
        * @param item
        * @param bean
        * @return
        */
       public SpannableString setClickableSpan(final String item, final UserBean bean) {
        final SpannableString string = new SpannableString(item);
        ClickableSpan span = new ClickableSpan() {
         @Override
         public void onClick(View widget) {
          // TODO: 2017/9/3 評論用戶名字點擊事件
          Toast.makeText(mContext, bean.getUserName(), Toast.LENGTH_SHORT).show();
         }
      
         @Override
         public void updateDrawState(TextPaint ds) {
          super.updateDrawState(ds);
          // 設置顯示的用戶名文本顏色
          ds.setColor(0xff387dcc);
          ds.setUnderlineText(false);
         }
        };
      
        string.setSpan(span, 0, string.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return string;
       }
      
       /**
        * 定義一個用于回調的接口
        */
       public interface onItemClickListener {
        void onItemClick(int position, CommentsBean bean);
       }
      }
      
      

      CircleMovementMethod

      public class CircleMovementMethod extends BaseMovementMethod {
       private final static int DEFAULT_COLOR_ID = android.R.color.transparent;
       /**
        * 整個textView的背景色
        */
       private int textViewBgColor;
       /**
        * 點擊部分文字時部分文字的背景色
        */
       private int clickableSpanBgClor;
      
       private BackgroundColorSpan mBgSpan;
       private ClickableSpan[] mClickLinks;
      
      
       /**
        * @param clickableSpanBgClor 點擊選中部分時的背景色
        */
       public CircleMovementMethod(int clickableSpanBgClor) {
        this.clickableSpanBgClor = clickableSpanBgClor;
       }
      
       /**
        * @param clickableSpanBgClor 點擊選中部分時的背景色
        * @param textViewBgColor  整個textView點擊時的背景色
        */
       public CircleMovementMethod(int clickableSpanBgClor, int textViewBgColor) {
        this.textViewBgColor = textViewBgColor;
        this.clickableSpanBgClor = clickableSpanBgClor;
       }
      
       public boolean onTouchEvent(TextView widget, Spannable buffer,
              MotionEvent event) {
      
        int action = event.getAction();
        if (action == MotionEvent.ACTION_DOWN) {
         int x = (int) event.getX();
         int y = (int) event.getY();
      
         x -= widget.getTotalPaddingLeft();
         y -= widget.getTotalPaddingTop();
      
         x += widget.getScrollX();
         y += widget.getScrollY();
      
         Layout layout = widget.getLayout();
         int line = layout.getLineForVertical(y);
         int off = layout.getOffsetForHorizontal(line, x);
      
         mClickLinks = buffer.getSpans(off, off, ClickableSpan.class);
         if (mClickLinks.length > 0) {
          // 點擊的是Span區(qū)域,不要把點擊事件傳遞
          Selection.setSelection(buffer,
            buffer.getSpanStart(mClickLinks[0]),
            buffer.getSpanEnd(mClickLinks[0]));
          //設置點擊區(qū)域的背景色
          mBgSpan = new BackgroundColorSpan(clickableSpanBgClor);
          buffer.setSpan(mBgSpan,
            buffer.getSpanStart(mClickLinks[0]),
            buffer.getSpanEnd(mClickLinks[0]),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
         } else {
          // textview選中效果
      //    widget.setBackgroundColor(textViewBgColor);
          widget.setBackgroundResource(DEFAULT_COLOR_ID);
         }
      
        } else if (action == MotionEvent.ACTION_UP) {
         if (mClickLinks.length > 0) {
          mClickLinks[0].onClick(widget);
          if (mBgSpan != null) {//移除點擊時設置的背景span
           buffer.removeSpan(mBgSpan);
          }
         } else {
      
         }
         Selection.removeSelection(buffer);
         widget.setBackgroundResource(DEFAULT_COLOR_ID);
        } else if (action == MotionEvent.ACTION_MOVE) {
         //這種情況不用做處理
        } else {
         if (mBgSpan != null) {//移除點擊時設置的背景span
          buffer.removeSpan(mBgSpan);
         }
         widget.setBackgroundResource(DEFAULT_COLOR_ID);
        }
        return Touch.onTouchEvent(widget, buffer, event);
       }
      }
      
      

      相關數據結構(模擬)

      CommentsBean

      public class CommentsBean implements Serializable {
       private int commentsId;
       private String content;
       private UserBean replyUser; // 回復人信息
       private UserBean commentsUser; // 評論人信息
      
       public int getCommentsId() {
        return commentsId;
       }
      
       public void setCommentsId(int commentsId) {
        this.commentsId = commentsId;
       }
      
       public String getContent() {
        return content;
       }
      
       public void setContent(String content) {
        this.content = content;
       }
      
       public UserBean getReplyUser() {
        return replyUser;
       }
      
       public void setReplyUser(UserBean replyUser) {
        this.replyUser = replyUser;
       }
      
       public UserBean getCommentsUser() {
        return commentsUser;
       }
      
       public void setCommentsUser(UserBean commentsUser) {
        this.commentsUser = commentsUser;
       }
      }
      
      

      UserBean

      public class UserBean implements Serializable {
       private int userId;
       private String userName;
      
       public int getUserId() {
        return userId;
       }
      
       public void setUserId(int userId) {
        this.userId = userId;
       }
      
       public String getUserName() {
        return userName;
       }
      
       public void setUserName(String userName) {
        this.userName = userName;
       }
      }
      
      

      用法

      
      
      commentView = LvV.find(this, R.id.commentView);
      commentView.setList(Data.getComments());
      commentView.setOnItemClickListener(new CommentsView.onItemClickListener() {
       @Override
       public void onItemClick(int position, CommentsBean bean) {
      
       }
      });
      commentView.notifyDataSetChanged();
      
      

      代碼已整理到Github

      附:如果需要完整朋友圈項目的話,這里推薦一個 Github 項目仿微信實現的朋友圈

      以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持創(chuàng)新互聯。


      本文名稱:Android實現朋友圈評論回復列表
      網址分享:http://www.ef60e0e.cn/article/pocies.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        安吉县| 兴宁市| 昭苏县| 东山县| 西华县| 义乌市| 冷水江市| 惠水县| 手游| 芜湖县| 调兵山市| 宝清县| 绩溪县| 永仁县| 中卫市| 攀枝花市| 宜宾县| 马边| 宜章县| 疏勒县| 湖北省| 蒲江县| 确山县| 潮安县| 金湖县| 南华县| 福贡县| 涞水县| 阳城县| 常德市| 新丰县| 东至县| 鹿泉市| 林芝县| 余庆县| 景德镇市| 韩城市| 盘山县| 桓台县| 增城市| 合山市|