Reputation: 396
Currently am developing an application for receiving messages and displaying them in the order which they came. But now am stuck at how to display these messages according to incoming and outgoing messages. I have a android phone with me.. In that messages are alligned to left and right. I want to display messages just like that..?? I know that using listview i can do that but how...? any advise..??
Upvotes: 0
Views: 1725
Reputation: 1518
Based on G_S's answer and Android's simple_list_item_1.xml, here is some xml code for that problem:
<?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="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight" >
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="6dip"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="6dip"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Upvotes: 0
Reputation: 7110
Try using relative layout and Consider two textViews in a layout and use them to inflate it to the list. For these two textViews consider using
android:layout_alignParentLeft="true"
to one and
android:layout_alignParentRight="true"
to another.
Upvotes: 1
Reputation: 67296
You can use getItemViewType()
and getViewTypeCount()
using BaseAdapter
and decide to display multiple rows with some logical condition. On the basis of View Type returned you can decide which view to display in List at which position. This blog
has a complete explanation how ListView works using different views too.
Upvotes: 3