Richten Sie zwei TextViews links und rechts in einer ListView aus, ohne die Hintergründe zu strecken

Also habe ich zweiTextViews pro Zeile in aListView. Einer sollte links und der andere rechts ausgerichtet sein. BeideTextViews haben Sie ein gerundetes Rechteck als Hintergrund, der den Text gerade nach innen einwickeln sollte. Also habe ich mir Folgendes ausgedacht:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/text_right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="@drawable/bubble_purple"
        android:gravity="center" >
    </TextView>

    <TextView
        android:id="@+id/text_left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/text_right"
        android:background="@drawable/bubble_blue"
        android:gravity="center" >
    </TextView>
</RelativeLayout>

Es sieht gut aus für lange Texte, aber nicht für kürzere Nachrichten:

Ich habe auch ein LinearLayout wie dieses ausprobiert:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/text_left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:background="@drawable/bubble_blue"
        android:gravity="center" >
    </TextView>

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/text_right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:background="@drawable/bubble_purple"
        android:gravity="center">
    </TextView>
</LinearLayout>

Dies funktioniert für kurze Nachrichten, aber nicht für längere:

Ist es irgendwie möglich die kombinierte Breite der zu messen?TextViews und programmgesteuert zwischen diesen Layouts wechseln, oder mache ich hier etwas falsch?

Antworten auf die Frage(1)

Ihre Antwort auf die Frage