2017-05-16 6 views
0

Wenn ich langen Text zu meinem TextView im linearen Layout hinzufügen, nimmt es den ganzen Raum ein, und andere Ansichten werden gequetscht. Ich habe layout_width="0" auf jede Ansicht gesetzt, aber es hat nicht geholfen. Ich sollte auch hinzufügen, dass dieses Layout in RecyclerView verwendet wird.LinearLayout TextView Gewicht bricht mit langem Text

Hier ist mein Code:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.LinearLayoutCompat 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:weightSum="100"> 

<TextView 
    android:textSize="12sp" 
    android:gravity="center" 
    android:id="@+id/lp" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:text="Lp" 
    android:layout_weight="5" /> 

//this TextView takes all the space if text is long, but it behaves normally if text is short 
<TextView 
    android:textSize="12sp" 
    android:gravity="center" 
    android:id="@+id/nazwa" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:text="Końcówka Yankauer do odsysania pola operacyjnego CH 23 (4 otwory boczne) z kontrolą odsysania" 
    android:layout_weight="20"/> 

<TextView 
    android:textSize="12sp" 
    android:gravity="center" 
    android:id="@+id/ilosc" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:text="#" 
    android:layout_weight="5" /> 

<TextView 
    android:textSize="12sp" 
    android:gravity="center" 
    android:id="@+id/jednostka" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:text="JM" 
    android:layout_weight="15" /> 

<TextView 
    android:textSize="12sp" 
    android:gravity="center" 
    android:id="@+id/cenaNetto" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:text="C. net." 
    android:layout_weight="15" /> 

<TextView 
    android:textSize="12sp" 
    android:gravity="center" 
    android:id="@+id/wartNetto" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:text="W.net." 
    android:layout_weight="15" /> 

<TextView 
    android:textSize="12sp" 
    android:gravity="center" 
    android:id="@+id/wartVAT" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:text="VAT" 
    android:layout_weight="10" /> 

<TextView 
    android:textSize="12sp" 
    android:gravity="center" 
    android:id="@+id/wartBrutto" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:text="W. brut." 
    android:layout_weight="15" /> 

</android.support.v7.widget.LinearLayoutCompat> 

hier ein Druckbild von dem, was in meiner app bricht link

+0

warum Sie verwenden Höhe "match_parent" für alle Textviews? –

+0

Wenn ich es nicht hässlich wie [dies] (http://i.imgur.com/e98BEBl.png) – musztardus

+0

Wenn Sie prozentualen Schraubstock sehen wollen, als versuchen, neue Konzept von android PercentRelativeLayout [Link] (https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html) – ashish

Antwort

1

Bitte versuchen Sie unten Link-Code als Demo Ich hoffe, Sie werden Ihr Ergebnis erhalten. Hier

ist der Code:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#ffffff" 
      android:shrinkColumns="*" 
      android:stretchColumns="*"> 
    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/row_my_booking_unit_name" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:gravity="center"> 
      </TextView> 
      <TextView 
       android:id="@+id/row_my_booking_unit_quantity" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:gravity="center"> 
      </TextView> 
      <TextView 
       android:id="@+id/row_my_booking_unit_amount" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:gravity="center"> 
      </TextView> 
     </LinearLayout> 
    </TableRow> 
</TableLayout> 
+0

Danke, das ist was ich gesucht habe, alles scheint jetzt richtig zu funktionieren. – musztardus

+0

Am meisten willkommen und thnk Sie für die Annahme meiner Antwort. – ashish

0

Sie dies in Ihrem TextView versucht, nicht wahr?

android:ellipsize="end" 
android:maxLines="1" 
+0

Ja, aber das Layout sieht immer noch genauso aus, nur mit weniger Text sichtbar. – musztardus

+0

@musztardus ist Ihre 'RecyclerView' horizontal? –

+0

[hier ist, wie es aussieht] (http://i.imgur.com/6zXPy8u.png) – musztardus

0

Wenn Sie möchten, dass jede Textansicht denselben Platz belegt, können Sie layout_weight = 1 für alle zuweisen.

+0

aber ich möchte nicht, dass jede Ansicht den gleichen Platz einnimmt. Ich möchte, dass jede Ansicht einen bestimmten Prozentsatz an Speicherplatz belegt, und es funktioniert, aber wenn ich in einer der Textansichten einen zu langen Text einstelle, bricht er. – musztardus

Verwandte Themen