【发布时间】:2013-10-21 11:54:12
【问题描述】:
我正在尝试在 android 中创建一个消息传递应用程序,并创建了一个自定义列表适配器,该适配器显示消息文本,然后显示日期。我已经让它们都显示了,现在希望它们能够以某种方式显示。我希望能够在屏幕的一侧发送消息,但在另一侧接收消息,日期显示在消息文本的下方/一侧
这是我为列表中的每个项目使用的自定义 xml,任何关于如何使它们正确包装并移动到屏幕两侧的想法将不胜感激!
(注意:我尝试过使用带权重的 LinearLayouts 和带 android:layout_alignParentRight 的 RelativeLayouts 等,但无法完全按照我的意愿使用它,所以我想在这里问一下!)
(认为不需要其他代码sn-ps,但如果需要可以提供!)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/msgTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:paddingRight="2dp"
android:textStyle="bold"
android:textSize="15sp" />
<TextView android:id="@+id/msgDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
干杯
【问题讨论】:
-
找出发送和接收的项目,然后制作固定宽度的文本视图(比如100dp)并根据发送/接收的消息左/右对齐。
-
RelativeLayout 非常适合这个,使用 alignParentLeft 或 alightParentRight。您可以根据需要在代码中进行设置。
标签: java android xml android-layout layout