本文由我司收集整编,推荐下载,如有疑问,请与我司联系
仿QQ聊天
2017/07/14 0 我们在聊QQ的时候会发现。QQ里面的列表,左右都可以显示头像与文字。其实在就是listView的item的多布局。下面来看一个实例。
这是怎么实现的呢?其中有两个要点。一个是listView加载了两个布局。一个就
是背景气泡。
先来看看加载两个布局。加载两个布局。肯定要有两个布局。下面是两个布局的代码。
左边布局
?xml version= 1.0 encoding= utf-8 ? LinearLayout xmlns:android= schemas.android/apk/res/android android:orientation= horizontal android:layout_width= match_parent android:layout_height= 80dp android:gravity= left ImageView android:id= @+id/chatleft_head android:layout_width= 50dp android:layout_height= 50dp android:layout_gravity= top / TextView android:id= @+id/chatleft_message android:layout_width= wrap_content android:layout_height= wrap_
android layout布局content android:layout_gravity= center_vertical android:background= @drawable/chat_left android:text= 消息android:textSize= 18sp / /LinearLayout 右边布局
?xml version= 1.0 encoding= utf-8 ? LinearLayout xmlns:android= schemas.android/apk/res/android android:orientation= horizontal android:layout_width= match_parent android:layout_height= 80dp android:gravity= right TextView android:id= @+id/chatright_message android:layout_width= wrap_content android:layout_height= wrap_content android:layout_gravity= center_vertical android:background= @drawable/chat_right android:text= 消息android:textSize= 18sp / ImageView android:id= @+id/chatright_head android:layout_width= 50dp android:layout_height= 50dp android:layout_gravity= top / /LinearLayout listView的布局我不贴了。既然做聊天界面,肯定不能显示item直接的间隔线。因此listView 里面加上这条属性android:divider= @null
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论