我正在尝试在 Android 中创建一个消息应用程序,并创建了一个自定义列表适配器,用于显示消息文本和日期。我已经让它们都显示了,现在希望它们能够以某种方式显示。我希望能够在屏幕的一侧发送消息,但在另一侧接收消息,日期显示在消息文本的下方/一侧
这是我为列表中的每个项目使用的自定义 xml,任何有关如何使它们适当换行并移动到屏幕两侧的想法将不胜感激!
(注意:我尝试过使用带有权重的 LinearLayouts 和带有 android:layout_alignParentRight 等的relativelayout,但无法完全按照我想要的方式得到它,所以我想在这里问!)
(认为不需要其他代码 fragment ,但如果需要的话可以提供!)
<?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>
干杯
最佳答案
I've tried using LinearLayouts with weights
这有什么问题吗? android:layout_weight="0.4"
尝试不使用“fill_parent”,而使用“match_parent”;
另外,替换这个
android:textSize="15sp"
对此:
android:textAppearance="?android:attr/textAppearanceMedium"
关于java - 消息传递应用程序 Android XML 的布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19493805/