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 7
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>
uns zeigen Sie Ihre XML-Datei –
Ich verwende constraintlayout – zihadrizkyef
fügen Sie XML-Datei –