2017-03-15 5 views
0

Momentan erstelle ich ein Layout für mein Chat ListView. Das Layout besteht aus einer Textansicht, die als Sprechblase fungiert, und daneben gibt es eine Textansicht für timeStamp. Das Problem mit meinem Layout ist, wenn mein Text sehr lang ist, schneidet der erste TextView den Platz, der vom zweiten TextView verwendet werden sollte. So verschwindet das zweite TextView.Textansicht im verschachtelten linearen Layout wird geschnitten?

Hier ist meine xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:paddingLeft="10dp" 
    android:paddingRight="40dp" 
    android:paddingBottom="10dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <TextView 
      android:text="sssssssssssssssssssyssssssssssssss" 
      android:padding="10dp" 
      android:background="@color/grey" 
      android:textColor="@color/white" 
      android:textSize="15sp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/chat_bubble" /> 
     <TextView 
      android:text="read" 
      android:textSize="8sp" 
      android:layout_marginLeft="5dp" 
      android:layout_gravity="left|bottom" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/time_label" /> 
    </LinearLayout> 

</LinearLayout> 

The textView is wrapping the text inside

+0

bitte diese Bibliothek überprüfen: https://github.com/DeromirNeves/whatsapp-android –

Antwort

1
Try this : 


    <?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:maxWidth="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="10dp" 
    android:paddingLeft="10dp" 
    android:paddingRight="40dp"> 

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

     <TextView 
      android:id="@+id/chat_bubble" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:padding="10dp" 
      android:text="Message Long Text" 
      android:textSize="15sp" /> 

     <TextView 
      android:id="@+id/time_label" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left|bottom" 
      android:layout_marginLeft="5dp" 
      android:text="read" 
      android:textSize="8sp" /> 
    </LinearLayout> 

</LinearLayout> 
+0

Von allen Antworten, das ist derjenige, der funktioniert. Alle anderen Antworten scheinen den gleichen Ansatz zu haben, indem Sie layout_weight auf 1 setzen, aber dieser setzt auch die innere LinearLayout-Breite auf wrap_content. Danke :) – VincentTheonardo

+0

Ihre Begrüßung @ VincentTheonardo .. :). Freue mich zu helfen – anil

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:gravity="left" 
android:paddingLeft="10dp" 
android:paddingRight="40dp" 
android:paddingBottom="10dp"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <TextView 
     android:text="sssssssssssssssssssyssssssssssssss" 
     android:padding="10dp" 
     android:background="@color/grey" 
     android:textColor="@color/white" 
     android:textSize="15sp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:id="@+id/chat_bubble" /> 
    <TextView 
     android:text="read" 
     android:textSize="8sp" 
     android:layout_marginLeft="5dp" 
     android:layout_gravity="center_vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/time_label" /> 
</LinearLayout> 

Ersetzen Sie den Code mit diesem Code.

+0

eigentlich möchte ich die Textview meine Inhalte wickeln, aber mit layout_weight = 1 die Chat-Blase wird zu groß für einen kleinen Text – VincentTheonardo

+0

okay, als Gewicht auf time_label textview geben. –

+0

Nein, es funktioniert nicht – VincentTheonardo

0

Bitte versuchen Sie es mit XML.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:paddingLeft="10dp" 
    android:paddingRight="40dp" 
    android:paddingBottom="10dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <TextView 
      android:text="sssssssssssssssssssyssssssssssssssssss" 
      android:padding="10dp" 
      android:background="@color/colorAccent" 
      android:textColor="@color/colorPrimary" 
      android:textSize="15sp" 
      android:layout_width="0dp" 
      android:layout_weight="0.90" 
      android:layout_height="wrap_content" 
      android:id="@+id/chat_bubble" /> 
     <TextView 
      android:text="read" 
      android:textSize="8sp" 
      android:layout_marginLeft="5dp" 
      android:layout_gravity="left|bottom" 
      android:layout_width="0dp" 
      android:layout_weight="0.10" 
      android:layout_height="wrap_content" 
      android:id="@+id/time_label" /> 
    </LinearLayout> 

</LinearLayout> 
+0

Nein, es funktioniert nicht. Genau wie die andere Antwort, die layout_weight macht es nicht möglich, entsprechend mit dem Zeichen innerhalb textView – VincentTheonardo

+0

skalieren bitte überprüfen Sie diese Bibliothek: https://github.com/DeromirNeves/whatsapp-android –

0

versuchen diese

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:gravity="left" 
android:paddingLeft="10dp" 
android:paddingRight="40dp" 
android:paddingBottom="10dp"> 


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <TextView 
     android:text="Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing" 
     android:padding="10dp" 
     android:background="@color/tabcolor" 
     android:textColor="@color/white" 
     android:textSize="15sp" 
     android:layout_width="150dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/chat_bubble" /> 
    <TextView 
     android:text="read" 
     android:textSize="8sp" 
     android:layout_marginLeft="5dp" 
     android:layout_gravity="left|bottom" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/time_label" /> 
</LinearLayout> 

</LinearLayout> 
+0

Durch Angabe der layout_width, die Breite wird statisch und nicht umhüllen meinen Inhalt – VincentTheonardo

+0

Sie machen eine Chat-App, so dass ich denke, Breite sollte auf die Hälfte der Bildschirmbreite statisch sein, so gebe ich diesen Code –

Verwandte Themen