代码之家  ›  专栏  ›  技术社区  ›  SoT

-文本视图过长时,布局会中断

  •  0
  • SoT  · 技术社区  · 6 年前

    我正在使用 RecyclerView 具有 ConstrainLayout 列出所有这样的文件

    Click me

    但是,当文本较长时,第一行和第二行之间的间距会增加(上图)。我不知道到底是什么问题。这是我的密码:

    item.xml:

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/layoutItem"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:foreground="?android:attr/selectableItemBackground">
    
            <ImageView
                android:id="@+id/imgFile"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="4dp"
                android:layout_marginTop="4dp"
                android:layout_marginBottom="4dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/ic_folder" />
    
            <TextView
                android:id="@+id/txtFileName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="4dp"
                android:layout_marginBottom="4dp
                app:layout_constraintBottom_toTopOf="@+id/txtLastModified"
                app:layout_constraintStart_toEndOf="@+id/imgFile"
                app:layout_constraintTop_toTopOf="parent" />
    
            <TextView
                android:id="@+id/txtLastModified"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginBottom="4dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toEndOf="@+id/imgFile"
                app:layout_constraintTop_toBottomOf="@+id/txtFileName" />
    
            <TextView
                android:id="@+id/txtAdditionalInfo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="12dp"
                app:layout_constraintBottom_toBottomOf="@+id/txtLastModified"
                app:layout_constraintStart_toEndOf="@+id/txtLastModified"
                app:layout_constraintTop_toTopOf="@+id/txtLastModified" />
    
        </android.support.constraint.ConstraintLayout>
    

    奖金:

    Layout

    1 回复  |  直到 6 年前
        1
  •  1
  •   AskNilesh    6 年前

    添加 android:maxLines="1" 对于 textview “txtFileName”