我在开发聊天应用,希望将时间戳放在聊天气泡旁边。消息将被左对齐(接收)和右对齐(发送)。因此,我正在寻找一种方法将“toLeftOf”更改为“toRightOf”。目前,它看起来像这样:
以下是每条消息的XML代码(我有一个处理此操作的ArrayAdapter)。但是,时间戳显示不正确,如下图所示:
我上网搜索并找到了这个,但是它不起作用:
有什么解决方案吗?谢谢。
以下是每条消息的XML代码(我有一个处理此操作的ArrayAdapter)。但是,时间戳显示不正确,如下图所示:
![Timestamp wrongly aligned](https://istack.dev59.com/0AikU.webp)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/bubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff" />
<TextView
android:id="@+id/timeStamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/bubble" />
</RelativeLayout>
我上网搜索并找到了这个,但是它不起作用:
。
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
if(isReceivedMessage){
params.addRule(RelativeLayout.RIGHT_OF, R.id.bubble);
}
else{
params.addRule(RelativeLayout.LEFT_OF, R.id.bubble);
}
timeStampTextView.setLayoutParams(params);
有什么解决方案吗?谢谢。