Android UI開發第四篇——實現像handcent sms或者chomp sms那樣的氣泡簡訊樣式

來源:互聯網
上載者:User

實現的是像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 attributesMap<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;}}

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_selected="true"        android:drawable="@android:color/transparent" />    <item android:state_pressed="true" android:state_selected="false"        android:drawable="@android:color/transparent" />    <item android:state_selected="false"          android:drawable="@android:color/white" /></selector>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.