Ich versuche, einen Chat-Bildschirm zu schreiben, der WhatsApp ähnelt, ich meine, empfangene Nachrichten ausgerichtet nach links, gesendete Nachrichten nach rechts ausgerichtet.Relative Layout Params funktioniert nicht richtig
Hier ist der Teil des Codes, wo ich MessageContainer mit den Nachrichten bevölkern.
msgbubble.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="match_parent">
<TextView
android:id="@+id/messageText"
android:padding="8dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hey there, it's been a while, how are you? :)"
android:background="@color/colorAccent"
android:textColor="@android:color/black"/>
</RelativeLayout>
activity_chat.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.messenger.ChatActivity">
<RelativeLayout
android:id="@+id/messageContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/msgPanel"
android:orientation="vertical">
</RelativeLayout>
<LinearLayout
android:id="@+id/msgPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Gönder"/>
</LinearLayout>
</RelativeLayout>
Aber alles was ich sehe ist, Nachrichten auf der jeweils anderen sind bei Standard (links) Ausrichtung .
Wie kann ich das beheben?
Was ist, wenn Ihre 'ChatList' 1000 Nachrichten enthält? Würden Sie Ihrem 'messageContainer' 1000 Ansichten hinzufügen? kennen Sie 'ListView' /' RecyclerView'? – pskink
Fügen Sie Ihre Nachricht xml hinzu. addView wird nicht funktionieren. Warum verwenden Sie keine vordefinierte Ansicht? – ADM
Sie müssen recycler Ansicht oder listview verwenden, um dies zu tun.Es wird nur nach Bildschirm begrenzen –