2016-07-14 5 views
1

Ich habe 2 TexView innen Linearlayout wie folgt:Linearlayout Gewicht Ausgabe für große/kleine Länge Text für Textviews

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

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

     <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/> 
</LinearLayout> 

Above Code weisen Sie den gleichen Raum sowohl Textview mit Ellipsen in Text, wenn der Text groß ist. Aber im Fall von weniger Länge des Textes, gibt es Raum zwischen beiden TextView.

{LargeTextFromTextView1... LargeTextFromTextView2...} 

{TextView1TextTextVeiw2Text   } 

Wie kann ich dies mit großen Text Case Handling loswerden.

Logic für die Ansicht Text:

Case1: Länge des Textes von TextView1 + Länge des Textes von TextView2 < = Bildschirmbreite zeigen einfach Text sowohl Textview

Case2: Länge des Textes von TextView1 + Länge der Text des TextView2> Bildschirmbreite Text TextView1 in ersten Halbteils mit ellipsen und Text von TextView2 im zweiten halben Teil mit ellipsen

Antwort

0
Create like this 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="2"> 
    <TextView 
    android:layout_width="@dimen/size_10dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"/> 
    <TextView 
    android:layout_width="@dimen/size_10dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"/> 
</LinearLayout> 

Edit: 

If textview should be single line and should end with ellipses use this: 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="2"> 
<TextView 
    android:layout_width="@dimen/size_10dp" 
    android:layout_height="wrap_content" 
    android:text="sdjhafdshfgdsfaudxzcxzcvvcvcvsfuafsdf" 
    android:layout_weight="1" 
    android:lines="1" 
    android:ellipsize="end"/> 
<TextView 
    android:layout_width="@dimen/size_10dp" 
    android:layout_height="wrap_content" 
    android:text="ddff" 
    android:layout_weight="1" 
    android:lines="1" 
    android:ellipsize="end"/> 
+0

Nicht arbeiten, Weisen Sie großen Text zum ersten und kleinen Text zum zweiten zu. Break down – Ajit

+0

@Ajit Sie wollen ... am Ende und Single-Line-Textansicht? – EagleEye

+0

ja, wenn der Text groß ist, dann muss mit ... enden – Ajit

0

<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/tx1" android:layout_width="100dp" android:layout_height="wrap_content" android:text="sdjhatfjhgjdhhvfygkjhkkkgftddrtyrtrd" android:lines="1" android:ellipsize="end" android:textSize="20sp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:text="ddff" android:id="@+id/tx2" android:layout_toRightOf="@+id/tx1" android:lines="1" android:ellipsize="end"/> </RelativeLayout>

Sie können für diese Anforderung ein relatives Layout verwenden. wenn das Ändern des Layouts kein Problem ist .. Sie stehen vor diesem Fehler, weil Sie GewichtSumme geben, es teilt den Bildschirm gleichmäßig, daher spielt es keine Rolle, wenn die erste Zeichenfolge Länge ist klein, es weist nur den zweiten Text Bilden Sie die andere Hälfte, damit Sie den Abstand zwischen ihnen erhalten