【发布时间】:2021-12-18 17:58:56
【问题描述】:
我有一个 RecyclerViewAdapter,我正在准备一个项目 xml 以将我的所有项目显示为列表。
我的 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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayoutAutoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:background="@drawable/bg_film_add_recycler_view">
<TextView
android:id="@+id/textViewFilmName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:textSize="16sp"
android:textColor="@color/figma_text_color_dark"
android:fontFamily="@font/inter500_regular"
app:layout_constraintBottom_toBottomOf="@id/imageViewFilmLogo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/imageViewFilmLogo"
app:layout_constraintTop_toTopOf="@id/imageViewFilmLogo"
tools:text="MyFilm">
</TextView>
<ImageView
android:id="@+id/imageViewFilmLogo"
android:layout_width="80dp"
android:layout_height="30dp"
android:layout_marginStart="30dp"
android:layout_marginVertical="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
</ImageView>
</androidx.constraintlayout.widget.ConstraintLayout>
因此,我看到我的 RecyclerView 是这样的(红色的是 textviews,绿色的是 imageviews):
如您所见,文本视图看起来像是在特定区域居中。但我想像这样向左对齐:
我尝试添加android:gravity="left",但它不起作用,是什么问题?你能帮帮我吗?
如果可能,您能否平衡“布局左边缘 - imageview”和“imageview - textview 左边缘”之间的距离
【问题讨论】:
标签: android xml android-layout textview android-constraintlayout