5

Ich habe eine relative Layout und zwei Textansichten. Textansicht 1 ist oben und links mit Eltern ausgerichtet. Textansicht 2 ist rechts von textview 1 und rechts von übergeordneten Elementen ausgerichtet. Dies erzeugt ein Problem, wenn der Text in 1 zu lang ist, was bedeutet, dass 1 im schlimmsten Fall 2 aus dem Bildschirm herausdrückt.TextView und Ellipsize, wenn durch andere TextView gequetscht

Wie bekomme ich diese zwei zu "opfern" von Text Nr 1 statt 2? minimale Breite scheint nicht zu funktionieren. Mein endgültiges Ziel ist es, Text 1 zu ellipsen, aber es scheint von der Textansicht abhängig zu sein, dass sie richtig dimensioniert ist.

Hier ist die XML-

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout android:id="@+id/RelativeLayout01" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       xmlns:android="http://schemas.android.com/apk/res/android"> 
<TextView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/TextView02" 
      android:layout_alignParentRight="true" 
      android:layout_toRightOf="@+id/TextView01" 
      android:text="I am number 2" 
      android:gravity="right" 
      android:lines="1" 
      android:minWidth="32sp"> 
</TextView> 
<TextView android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:id="@+id/TextView01" 
      android:layout_alignParentLeft="true" 
      android:textSize="22sp" 
      android:layout_width="wrap_content" 
      android:lines="1" 
      android:text="sd sd asd sad asd asd saasd a"> 
</TextView> 

</RelativeLayout> 
+3

Eigentlich ist dies perfekt mit dieser Frage beantwortet: http://stackoverflow.com/questions/3785221/two-textviews-side-by-side-only-one-to-ellipsize – sandos

Antwort

0

Sie können dies ganz einfach mit einem horizontalen Linearlayout mit Gewicht Attribute. Der folgende Code funktioniert für Sie. Ich setze auch IDs für deine Ansichten, also kopiere einfach das und es wird in deinem Code funktionieren.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:orientation="horizontal" 
    > 
    <TextView 
     android:id="@+id/TextView01" 
     android:layout_height="wrap_content" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:ellipsize="end" 
     android:maxLines="1" 
     android:text="Some Long and Random Text Some Long and Random Text" 
     /> 
    <TextView 
     android:id="@+id/TextView02" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_weight="0" 
     android:layout_gravity="right"  
     android:text="I am number 2" 
    /> 
</LinearLayout> 
+1

Ich habe ein Problem mit dieser Lösung In meinem Projekt ist der erste Text ellipsenförmig, wie es sein sollte, aber hinterlässt einen leeren Raum am Ende, weil er ganze Wörter verkürzt (und der letzte ist ziemlich "lang"), so dass der zweite Text weiter entfernt ist, als er sein sollte . Irgendeine Lösung dazu – Squeazer

0

get Idee von meinem Textview und benutzen Sie einfach Ihre Textview wie diese, hoffe, es ist Arbeit:

    <TextView 
        android:id="@+id/tv_songtitle" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="5dp" 
        android:text="Song Title" 
        android:singleLine="true" 
        android:ellipsize="end" 
        android:textSize="13dp" 
        android:textStyle="bold" /> 
0

Verwenden Attribut android:shrinkColumns="0" von TableLayout.