Android UI开发第四篇——实现像handcent sms或者chomp sms那样的气泡短信样式


今晚有点时间把断了很长时间的UI开发补一下,这次实现的是像handcent sms或者chomp sms那样的气泡短信样式,也是iphone上的气泡聊天模式。实现这种效果的重点是ListView的divider和listSelector。先看一下效果图。

给代码:
(1)listview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    >
  <ListView
    android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@null"
android:dividerHeight="0dip"
android:cacheColorHint="#00000000"
android:listSelector="@drawable/list_item_style"
android:id="@+id/itemlist" />
</LinearLayout>
 
(2)ListView item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
 
<TextView android:id="@+id/TextView01"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textColor="@android:color/black"     
       android:background="@drawable/bg"></TextView>
</LinearLayout>
 
(3)java:
 
public class HandcentList extends Activity {
    /** Called when the activity is first created. */
ListView itemlist = null;
List<Map<String, Object>> list;
   
final String[] str={"A","B","C","D","E","F"};
/** Called when the activity is first created. */
 
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
itemlist = (ListView) findViewById(R.id.itemlist);
refreshListItems();
}
private void refreshListItems() {
list = buildListForSimpleAdapter();
SimpleAdapter notes = new SimpleAdapter(this, list, R.layout.item,
new String[] { "str" }, new int[] { R.id.TextView01,});
itemlist.setAdapter(notes);
itemlist.setSelection(0);
}
private List<Map<String, Object>> buildListForSimpleAdapter() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(2);
// Build a map for the attributes
Map<String, Object> map = new HashMap<String, Object>();
map.put("str", "呵呵呵呵呵");
list.add(map);
 
map = new HashMap<String, Object>();
map.put("str", "呵呵");
list.add(map);
 
map = new HashMap<String, Object>();
map.put("str", "呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵");
list.add(map);
 
map = new HashMap<String, Object>();
map.put("str", "呵呵呵呵呵呵");
list.add(map);
 
map = new HashMap<String, Object>();
map.put("str", "呵呵呵呵呵呵呵呵呵呵\n呵呵呵呵\n呵呵\n呵呵");
list.add(map);
 
map = new HashMap<String, Object>();
map.put("str", "呵呵呵呵呵呵呵呵呵呵呵呵呵呵\n呵呵呵呵");
list.add(map);
return list;
}
}
 

http://www.devdiv.com/home.php?mod=space&uid=14682&do=blog&id=2518




     本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/817381,如需转载请自行联系原作者


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值