關(guān)于android 聊天頁面 類似泡泡包裹聊天內(nèi)容的實現(xiàn)

本文 附加的代碼 demo 就是實現(xiàn)聊天頁面類似微信垫挨,陌陌等聊天信息被泡泡包裹锋拖。使得頁面展示美觀專業(yè)诈悍。 demo中包含了使用的切圖,包含了布局兽埃,以及代碼控制侥钳。本demo只是在UI上的實現(xiàn),不沒有實現(xiàn)完成的通信功能柄错,對于聊天社交app,服務(wù)器交互很重要舷夺。比如消息的緩存苦酱,消息實時接收,延時接收给猾,在線心跳等疫萤。

主頁面就是一個listview:


android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id?="@+id/MessageBox"

android:layout_alignParentBottom?="true"

>

android:layout_width?="200dip"

android:layout_height?="50dip"

android:layout_marginLeft?="50dip"

android:text?="輸入聊天內(nèi)容"

android:textSize="18dip"

android:id?="@+id/MessageText"

/>

android:layout_width?="wrap_content"

android:layout_height?="50dip"

android:layout_alignParentRight?="true"

android:text?="發(fā)送"

android:textSize="18dip"

android:id?="@+id/MessageButton"

/>

android:id="@+id/list"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignParentTop?="true"

android:layout_above?="@+id/MessageBox"

/>


然后實現(xiàn)item,區(qū)分接收和自己發(fā)送

接收的item布局


xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:layout_marginLeft="10px"

>

android:orientation="vertical"

android:layout_width="249px"

android:layout_height="wrap_content"

android:background="@drawable/outgoing"

>

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="22dip"

>

android:id="@+id/messagedetail_row_name"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#000000"

android:paddingTop="2px"

android:textSize="16dip"

/>

android:id="@+id/messagedetail_row_date"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#000000"

android:paddingTop="2px"

android:textSize="16dip"

android:layout_marginLeft="60dip"

/>

android:id="@+id/messagedetail_row_text"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:paddingLeft="2px"

android:textColor="#0000DD"

android:textSize="16dip"

/>

android:layout_width="42px"

android:layout_height="42px"

android:layout_gravity="bottom"

android:id="@+id/messagegedetail_rov_icon"

android:background="@drawable/retouxiang"

/>


自己發(fā)送item:


xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

>

android:layout_width="42px"

android:layout_height="42px"

android:layout_gravity="bottom"

android:id="@+id/messagegedetail_rov_icon"

android:background="@drawable/retouxiang"

/>

android:orientation="vertical"

android:layout_width="249px"

android:layout_height="wrap_content"

android:background="@drawable/incoming"

>

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="22dip"

>

android:id="@+id/messagedetail_row_name"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#000000"

android:paddingTop="2px"

android:textSize="16dip"

/>

android:id="@+id/messagedetail_row_date"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#000000"

android:paddingTop="2px"

android:textSize="16dip"

android:layout_marginLeft="60dip"

/>

android:id="@+id/messagedetail_row_text"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:paddingLeft="2px"

android:textColor="#0000DD"

android:textSize="16dip"

/>


使用的切圖是.9圖片:

代碼控制就是acticity中代碼和編寫的listview 適配器敢伸。詳細(xì)實現(xiàn)請下載demo查看扯饶。

demo 下載處

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市详拙,隨后出現(xiàn)的幾起案子帝际,更是在濱河造成了極大的恐慌,老刑警劉巖饶辙,帶你破解...
    沈念sama閱讀 218,386評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蹲诀,死亡現(xiàn)場離奇詭異,居然都是意外死亡弃揽,警方通過查閱死者的電腦和手機脯爪,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,142評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來矿微,“玉大人痕慢,你說我怎么就攤上這事∮渴福” “怎么了掖举?”我有些...
    開封第一講書人閱讀 164,704評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長娜庇。 經(jīng)常有香客問我塔次,道長,這世上最難降的妖魔是什么名秀? 我笑而不...
    開封第一講書人閱讀 58,702評論 1 294
  • 正文 為了忘掉前任励负,我火速辦了婚禮,結(jié)果婚禮上匕得,老公的妹妹穿的比我還像新娘继榆。我一直安慰自己,他們只是感情好汁掠,可當(dāng)我...
    茶點故事閱讀 67,716評論 6 392
  • 文/花漫 我一把揭開白布略吨。 她就那樣靜靜地躺著,像睡著了一般考阱。 火紅的嫁衣襯著肌膚如雪翠忠。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,573評論 1 305
  • 那天羔砾,我揣著相機與錄音负间,去河邊找鬼偶妖。 笑死,一個胖子當(dāng)著我的面吹牛政溃,可吹牛的內(nèi)容都是我干的趾访。 我是一名探鬼主播,決...
    沈念sama閱讀 40,314評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼董虱,長吁一口氣:“原來是場噩夢啊……” “哼扼鞋!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起愤诱,我...
    開封第一講書人閱讀 39,230評論 0 276
  • 序言:老撾萬榮一對情侶失蹤云头,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后淫半,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體溃槐,經(jīng)...
    沈念sama閱讀 45,680評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,873評論 3 336
  • 正文 我和宋清朗相戀三年科吭,在試婚紗的時候發(fā)現(xiàn)自己被綠了昏滴。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,991評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡对人,死狀恐怖谣殊,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情牺弄,我是刑警寧澤姻几,帶...
    沈念sama閱讀 35,706評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站势告,受9級特大地震影響蛇捌,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜培慌,卻給世界環(huán)境...
    茶點故事閱讀 41,329評論 3 330
  • 文/蒙蒙 一豁陆、第九天 我趴在偏房一處隱蔽的房頂上張望柑爸。 院中可真熱鬧吵护,春花似錦、人聲如沸表鳍。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,910評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽譬圣。三九已至瓮恭,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間厘熟,已是汗流浹背屯蹦。 一陣腳步聲響...
    開封第一講書人閱讀 33,038評論 1 270
  • 我被黑心中介騙來泰國打工维哈, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人登澜。 一個月前我還...
    沈念sama閱讀 48,158評論 3 370
  • 正文 我出身青樓阔挠,卻偏偏與公主長得像,于是被迫代替她去往敵國和親脑蠕。 傳聞我的和親對象是個殘疾皇子购撼,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,941評論 2 355