android - 如何在 ImageView 旁边居中两个 TextView?
问题描述
我正在尝试实现以下输出:
但我得到的是:
我似乎无法弄清楚如何使两者居中TextViews
。编码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/chat_room_image_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Progress bar -->
<ProgressBar
android:id="@+id/chat_room_image_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:maxHeight="40dp"
android:minHeight="40dp"
android:minWidth="40dp"
android:maxWidth="40dp"
android:theme="@style/progressColor"
android:layout_margin="15dp" />
<!-- user's avatar image -->
<ImageView
android:id="@+id/chat_room_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp" />
</RelativeLayout>
<LinearLayout
android:id="@+id/chat_room_title_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@id/chat_room_image_layout"
android:layout_toEndOf="@id/chat_room_image_layout">
<!-- user names -->
<TextView
android:id="@+id/chat_room_users_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/blackColor"
android:includeFontPadding="false"
android:layout_marginTop="10dp"/>
<!-- last message -->
<TextView
android:id="@+id/chat_room_last_message_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="15sp"
android:text="aaaaaaaaaaaaaaaaaaaaa"
android:includeFontPadding="false"
android:textColor="@color/blackColor"
android:layout_marginBottom="10dp" />
</LinearLayout>
</RelativeLayout>
化身的身高和体重是动态设置的50dp
。我厌倦了关注这个话题,但没有任何成功。我怎样才能使这两个文本视图居中?
解决方案
您可以使用:
<LinearLayout
android:layout_height="wrap_content"
android:minHeight="56dp"
android:layout_width="match_parent">
<!-- user's avatar image -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingStart="15dp"
android:paddingEnd="15dp"/>
<!-- Progress bar -->
<ProgressBar
android:id="@+id/chat_room_image_progressbar"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
..>
<LinearLayout
android:id="@+id/chat_room_title_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">
<!-- user names -->
<TextView
android:id="@+id/chat_room_users_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
.../>
<!-- last message -->
<TextView
android:id="@+id/chat_room_last_message_text"
android:text="text2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
... />
</LinearLayout>
</LinearLayout>
推荐阅读
- c# - 如何在特殊字符前后添加空格
- mysql - 左外连接适用于 SQLite,而不适用于 MySQL
- python - 使用 for 循环将函数输出分配给列表中的变量
- python - 使用 for 循环通过 try 和 except 遍历数字列表
- json - 如何在 VBA 中解析嵌套的 JSON
- r - R语法中的自动更新日期
- c++ - 现代 OpenGL 和 GLEW Libraray 的编译错误
- webauthn - 关于 FIDO2 webauthn 和 U2F 的几个开放性问题
- r - ry 不是季节性 ts 对象
- javascript - 自定义按钮仅在 HTML 列表中的第一个元素处起作用