Android PraiseTextView實(shí)現(xiàn)朋友圈點(diǎn)贊功能
PraiseTextView
說明
我是將朋友圈分成了幾個(gè)獨(dú)立模塊單獨(dú)自定義的View,通過回調(diào)完成交互,耦合性算是非常低了,主要有以下及部分:
1.評(píng)論布局(自定義TextView)
2.點(diǎn)贊布局(原理和評(píng)論的自定義TextView一樣,都是用的SpannableString)
3.圖片列表(出門右轉(zhuǎn),理論上沒有數(shù)量限制,和listView配合使用也很好,緩存也自己處理了)
我也是找第三方例子不好找,于是自己寫了一個(gè),我和同事還打算做一套IM系統(tǒng),app和后臺(tái)都要做,我們自己定義sdk,我們還要封裝H5,類似hbuilder如果有什么問題,可以聯(lián)系我。
全是跳轉(zhuǎn)到GitHub上的鏈接,源碼也在GitHub上
示例
主要方法
mPraiseTextView.setData (mPraiseInfos);//設(shè)置數(shù)據(jù) mPraiseTextView.setNameTextColor (Color.BLUE);//設(shè)置名字字體顏色 mPraiseTextView.setIcon (R.drawable.emoji_1f0cf);//設(shè)置圖標(biāo) mPraiseTextView.setMiddleStr (",");//設(shè)置分割文本 mPraiseTextView.setIconSize (new Rect (0,0,100,100));//設(shè)置圖標(biāo)大小,默認(rèn)與字號(hào)匹配 mPraiseTextView.setonPraiseListener()//設(shè)置監(jiān)聽
onClick (int position, PraiseTextView.PraiseInfo mPraiseInfo)
position是第幾個(gè)點(diǎn)贊的人,mInfo是這條點(diǎn)贊的信息
onOtherClick
內(nèi)部處理了點(diǎn)擊文字會(huì)觸發(fā)兩個(gè)回調(diào)的問題,這個(gè)是點(diǎn)擊非文字或者沒有單獨(dú)定義點(diǎn)擊事件的回調(diào)
布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.lujianchao.praisetextview.MainActivity"> <com.lujianchao.praisetextview.PraiseTextView android:layout_width="match_parent" android:id="@+id/praisetextview" android:layout_height="wrap_content" /> <TextView android:id="@+id/log" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical"/> </LinearLayout>
代碼
public class MainActivity extends AppCompatActivity { private PraiseTextView mPraiseTextView; private TextView mTextView; @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); mPraiseTextView = (PraiseTextView) findViewById (R.id.praisetextview); mTextView = (TextView) findViewById (R.id.log); mTextView.setMovementMethod (ScrollingMovementMethod.getInstance ()); List<PraiseTextView.PraiseInfo> mPraiseInfos = new ArrayList<> (); mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (111).setNickname ("張三").setLogo ("http://lujianchao.com/images/headimg/1.jpg")); mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (222).setNickname ("張四").setLogo ("http://lujianchao.com/images/headimg/2.jpg")); mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (333).setNickname ("張五").setLogo ("http://lujianchao.com/images/headimg/3.jpg")); mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (444).setNickname ("張六").setLogo ("http://lujianchao.com/images/headimg/4.jpg")); mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (555).setNickname ("趙四").setLogo ("http://lujianchao.com/images/headimg/5.jpg")); mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (666).setNickname ("趙三").setLogo ("http://lujianchao.com/images/headimg/6.jpg")); mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (777).setNickname ("李大").setLogo ("http://lujianchao.com/images/headimg/7.jpg")); mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (888).setNickname ("李二").setLogo ("http://lujianchao.com/images/headimg/8.jpg")); mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (999).setNickname ("李三").setLogo ("http://lujianchao.com/images/headimg/9.jpg")); mPraiseTextView.setData (mPraiseInfos);//設(shè)置數(shù)據(jù) mPraiseTextView.setNameTextColor (Color.BLUE);//設(shè)置名字字體顏色 mPraiseTextView.setIcon (R.drawable.emoji_1f0cf);//設(shè)置圖標(biāo) mPraiseTextView.setMiddleStr (",");//設(shè)置分割文本 mPraiseTextView.setIconSize (new Rect (0,0,100,100));//設(shè)置圖標(biāo)大小,默認(rèn)與字號(hào)匹配 mPraiseTextView.setonPraiseListener (new PraiseTextView.onPraiseClickListener () { @Override public void onClick (final int position, final PraiseTextView.PraiseInfo mPraiseInfo) { mTextView.append ("position = [" + position + "], mPraiseInfo = [" + mPraiseInfo + "]"+"\r\n"); } @Override public void onOtherClick () { mTextView.append ("onOtherClick"+"\r\n"); } }); } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 簡(jiǎn)單實(shí)用的Android UI微博動(dòng)態(tài)點(diǎn)贊效果
- Android 仿微信朋友圈點(diǎn)贊和評(píng)論彈出框功能
- Android項(xiàng)目開發(fā) 教你實(shí)現(xiàn)Periscope點(diǎn)贊效果
- Android中Listview點(diǎn)贊功能的實(shí)現(xiàn)
- Android實(shí)現(xiàn)點(diǎn)贊動(dòng)畫(27)
- Android中使用PopupWindow 仿微信點(diǎn)贊和評(píng)論彈出
- Android Listview點(diǎn)贊問題關(guān)于圖片重復(fù)問題
- Android實(shí)現(xiàn)朋友圈點(diǎn)贊列表
- Android高級(jí)UI特效仿直播點(diǎn)贊動(dòng)畫效果
- Android控件FlowLikeView實(shí)現(xiàn)點(diǎn)贊動(dòng)畫
相關(guān)文章
Android自定義View實(shí)現(xiàn)彈幕效果
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)彈幕效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11Android組合式自定義控件實(shí)現(xiàn)購(gòu)物車加減商品操作
這篇文章主要介紹了Android組合式自定義控件實(shí)現(xiàn)購(gòu)物車加減商品操作,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11