2012-09-10 51 views
0

目前,我正在开发一个接收消息并按照它们来的顺序显示它们的应用程序。但现在我坚持如何根据传入和传出的消息显示这些消息。我有一个Android手机与我..在该消息被分配左侧和右侧。我想显示消息就像那样.. ??我知道使用listview我可以做到这一点,但如何......?任何建议.. ??如何设置列表视图项目左右像对话..?

回答

1

尝试使用相对布局和 考虑布局中的两个textView并使用它们将其充气到列表中。 对于这两个textViews考虑使用

android:layout_alignParentLeft="true" 

一个和

android:layout_alignParentRight="true" 

到另一个。

+0

你必须提到这是可能只使用'相对Layout'。如果OP使用“线性布局”,您的答案将无法使用。 –

+0

是的,你是对的 –

+0

其不适合我..我使用relativelayout –

3

您可以使用getItemViewType()getViewTypeCount()使用BaseAdapter并决定显示具有某种逻辑条件的多行。在返回的视图类型的基础上,您可以决定在哪个位置显示List中的哪个视图。 This blog有一个完整的解释,ListView如何使用不同的视图。

0

基于G_S的答案和Android的simple_list_item_1.xml,这里是该问题的一些XML代码:

<?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> 
相关问题