首页 > 解决方案 > 安卓用户界面元素

问题描述

我想创建一个 UI 类似这样的列表。

用户界面元素

我无法使用两个 TextView 创建相同的 UI。请帮我弄清楚如何仅使用两个 TextView 来创建此 UI。

名称的第一个 TextView (James)
消息的第二个 TextView (带我...)

提前致谢。

标签: androiduser-interfaceandroid-xml

解决方案


您可以像这样使用约束布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textTitle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:constraintStart_toEndOf="@id/image"
        app:constraintEnd_toEndOf="parent" />

    <TextView
        android:id="@+id/textMessage"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:constraintTop_topBottomOf="@id/textTitle"
        app:constraintStart_toEndOf="@id/image"
        app:constraintEnd_toEndOf="parent" /> 

</androidx.constraintlayout.widget.ConstraintLayout>

推荐阅读