【发布时间】:2021-11-25 22:45:18
【问题描述】:
我想在 textview 之前放置两个 Imageview。当 textview 是单行时,我会得到所需的输出,见下文
如果文本视图是多行的,则会添加额外的空间,我不知道如何修复它。这是图片和代码
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/title_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp16"
android:layout_marginTop="@dimen/dp18"
android:layout_marginEnd="@dimen/dp16"
android:orientation="horizontal"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/som_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/dp8"
android:src="@drawable/ic_info_icon"
app:layout_constraintBottom_toBottomOf="@id/name_details"
app:layout_constraintEnd_toStartOf="@id/name_details" />
<ImageView
android:id="@+id/hand_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/dp8"
android:src="@drawable/ic_hand"
app:layout_constraintBottom_toBottomOf="@id/name_details"
app:layout_constraintEnd_toStartOf="@id/name_details" />
<TextView
android:id="@+id/name_details"
style="@style/sharp_sans_semi_bold_20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
tools:text="Mynameis RachelKaren " />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
-
当我将您的代码复制并粘贴到一个空项目中时,它会显示所需的行为(除了我将
@dimen/dpX替换为Xdp并删除了文本视图的样式标签,因为我没有t 有这些值)。
标签: android android-layout android-constraintlayout constraint-layout-chains