android - 如何在whatsapp中左右对齐android聊天应用程序
问题描述
我在 youtube 上关注一个 tuuriol 来创建一个聊天应用程序。我面临的问题是我似乎没有像whatsapp那样显示聊天,就像发件人应该在右边,而用户应该在右边。我尝试了几种方法,使用 if else 语句似乎与一侧对齐。这是我的代码。它与其他问题不同,因为我有 2 个不同的 xml,并且我正在尝试使用 java
chat_item_left.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.github.library.bubbleview.BubbleTextView
android:layout_alignParentStart="true"
android:layout_marginTop="5dp"
android:layout_below="@id/messageUser"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="#FFF"
android:textSize="18sp"
android:id="@+id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
app:arrowWidth="8dp"
app:angle="8dp"
app:arrowHeight="10dp"
app:arrowPosition="14dp"
app:arrowLocation="left"
app:bubbleColor="#333639"
app:arrowCenter="true"
android:text="hie"
android:layout_alignParentLeft="true" />
chat_item_right.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.github.library.bubbleview.BubbleTextView
android:layout_alignParentEnd="true"
android:layout_marginTop="5dp"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="#FFF"
android:textSize="18sp"
android:id="@+id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
app:arrowWidth="8dp"
app:angle="8dp"
app:arrowHeight="10dp"
app:arrowPosition="14dp"
app:arrowLocation="right"
app:bubbleColor="@android:color/holo_blue_bright"
app:arrowCenter="true"
android:text="hie"
android:layout_alignParentRight="true" />
这是我到目前为止对我的代码所做的事情
private void displayChatMessage() {
ListView listOfMessage = (ListView) findViewById(R.id.listOfMessage);
Query query = FirebaseDatabase.getInstance().getReference().child("chats");
FirebaseListOptions<ChatMessage> options = new FirebaseListOptions.Builder<ChatMessage>()
.setLayout(R.layout.chat_item_left)
.setQuery(query, ChatMessage.class)
.build();
adapter = new FirebaseListAdapter<ChatMessage>(options) {
@Override
protected void populateView(View v, ChatMessage model, int position) {
// Bind the Chat to the view
// ...
//get references to views of list_item.xml
TextView messageText ,messageUser,messageTime;
messageText = (BubbleTextView) v.findViewById(R.id.messageText);
messageText.setText(model.getMessageText());
}
};
listOfMessage.setAdapter(adapter);
}
我在哪里指定放置正确的对齐?
解决方案
推荐阅读
- ios - KVStore 标识符的 Xcode 10 iCloud 权利值不匹配错误
- python - 如何让内循环考虑外循环的每次迭代?
- c# - C# - 取决于数据库行的动态 URL
- c# - 添加重定向时,串联的动态 URL 字符串停止工作
- c++ - Qwt Plot:如何减少图例项之间的间距
- java - Thymeleaf 动态字段,Spring boot
- sql - String_Split 表的值
- reactjs - Old state still exist even after updating state in react
- typescript - 在 TypeScript 中使用“T”前缀类型名称和使用“I”作为接口名称前缀是不是很好?
- selenium - 新标签浏览器 URL selenium C#