2017-08-21 19 views
-1

Ich habe eine Textansicht, deren Höhe von der Größe der Höhe der Bildansicht abhängt, und die Bildbreite beträgt 30% der Bildschirmgröße. Ich setze die Textansicht mit Maxlines = 2 und Ellipsize = Ende. Es funktioniert gut in Nexus S, aber nicht gut in größeren Bildschirm wie uns Nexus 7, weil Maxlines 2 nicht größer ist. Wie man Maxlines vergrößert, hängt von der Bildschirmgröße ab.Textansicht maxlines hängt von seiner Höhe ab

Nexus S

Nexus S

Nexus 7

enter image description here

Und dies ist der Code

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_orientation="vertical"> 

    <TextView 
     android:id="@+id/tvName" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="Nama" 
     android:textSize="24sp" 
     android:textStyle="bold" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintLeft_toRightOf="@+id/ivPhotoProfile" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     app:layout_constraintHorizontal_bias="0.0"/> 

    <TextView 
     android:id="@+id/tvUsername" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="0dp" 
     android:layout_marginRight="0dp" 
     android:layout_marginTop="-1dp" 
     android:text="Username" 
     android:textSize="12sp" 
     app:layout_constraintLeft_toLeftOf="@+id/tvName" 
     app:layout_constraintRight_toRightOf="@+id/tvName" 
     app:layout_constraintTop_toBottomOf="@+id/tvName"/> 

    <TextView 
     android:id="@+id/tvBio" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginBottom="0dp" 
     android:layout_marginLeft="0dp" 
     android:layout_marginRight="0dp" 
     android:layout_marginTop="2dp" 
     android:ellipsize="end" 
     android:maxLines="2" 
     android:text="@string/lorem_ipsum" 
     android:textSize="14sp" 
     app:layout_constraintBottom_toBottomOf="@+id/ivPhotoProfile" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="@+id/tvUsername" 
     app:layout_constraintRight_toRightOf="@+id/tvUsername" 
     app:layout_constraintTop_toBottomOf="@+id/tvUsername"/> 

    <ImageView 
     android:id="@+id/ivPhotoProfile" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="0dp" 
     android:layout_marginTop="8dp" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     app:layout_constraintDimensionRatio="1:1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/guideline2" 
     app:layout_constraintTop_toTopOf="parent" 
     app:srcCompat="@drawable/profile_picture_default"/> 

    <android.support.constraint.Guideline 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/guideline2" 
     android:orientation="vertical" 
     app:layout_constraintGuide_percent="0.30625"/> 

</android.support.constraint.ConstraintLayout> 
+0

uns zeigen Sie Ihre XML-Datei –

+0

Ich verwende constraintlayout – zihadrizkyef

+2

fügen Sie XML-Datei –

Antwort

2

mit Versuchen unter Leitung von <TextView android:id="@+id/tvBio" ... xml zu entfernen: -

app:layout_constraintBottom_toBottomOf="@+id/ivPhotoProfile" 
+0

es geht nicht um die Höhe der Ansicht, aber die Maxlines der Textansicht – zihadrizkyef

+0

Wenn die Höhe größer ist, möchte ich die Maxlines auch größer sein .. – zihadrizkyef

2

Setzen Sie nicht maxlines nur Ihre Textview android machen: ellipsize = und richten Sie Ihre Textview "Ende" unten zu imageview bottom nimmt es automatisch maxlines nach s ize Ihrer Textview und halten Sie Ihre Textview ausgerichtet auf Ihre Imageview

+0

alignedToBottom der Bildansicht, so dass es entsprechend Bildansichten Höhe geändert wird. –

+0

wenn ich maxlines nicht gesetzt ist, dann ist ellipsize nicht – zihadrizkyef

+0

versuchen arbeiten dann so etwas wie dies zu tun: ** android: layout_width = "match_parent" android: layout_height = "wrap_content" android: ellipsize = "Ende " android: maxLines =" 5 " android: minLines =" 2 "** in denen maxlines die Zeilen sind, die Sie auf großen Geräten einstellen möchten – YoLo

Verwandte Themen