很多聊天軟體都模仿這個功能,
像是FB、 whatsapp、Line、weChat等等,
其實只需要用ListView去修改即可,
故接續上一個ListView的範例,
我們先在drawble資料夾放入兩張泡泡圖片,
在隨便拉一張背景圖後按reflash,
修改上一個範例中的list.xml這個layout,
將泡泡圖案加textView的背景裡,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:text="TextView"
android:textColor="@color/blue"
android:background="@drawable/bubble_yellow"
android:gravity="left"
/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/name"
android:layout_marginRight="14dp"
android:layout_marginTop="24dp"
android:background="@drawable/bubble_green"
android:gravity="right"
android:text="TextView" />
</RelativeLayout>
然而listView有一些預設屬性像是每一個row會有底線、拉動時每個row會有橘色的背景,
必須將這些東西拿掉,
底線的部分可以在主程式中加入一行:
istView.setDividerHeight(0); //隱藏listView底線
背景色的部分到main.xml的layout對listView修改,
1.加入背景圖片
android:background="@drawable/cloud"
2.將選取的橘色背景改為透明
android:cacheColorHint="@android:color/transparent"
android:listSelector="@android:color/transparent"
泡泡對話框就完成了:
沒有留言:
張貼留言