【发布时间】:2021-12-16 03:37:03
【问题描述】:
我正在尝试将文本视图放置在图像视图的右侧。虽然我能够做到这一点,但当我将匹配父级提供给文本视图时,我遇到了问题。我希望文本覆盖剩余区域,但是当我使用匹配父级时,它会与左侧的图像视图重叠。 这是我的代码
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_default"
android:layout_marginTop="12dp"
android:layout_marginEnd="@dimen/margin_default"
android:layout_marginBottom="12dp">
<ImageView
android:id="@+id/effective_warnings_card_icon"
android:layout_width="48dp"
android:layout_height="0dp"
android:focusable="false"
android:importantForAccessibility="no"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="@id/effective_warnings_card_text"
app:srcCompat="@drawable/account_unavailable_image"
tools:src="@tools:sample/avatars" />
<TextView
android:id="@+id/effective_warnings_card_text"
style="@style/TextAppearance.TSBApp20.Body.Regular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:text="aggfgffh"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/effective_warnings_card_icon"
app:layout_constraintStart_toEndOf="@+id/effective_warnings_card_icon"
app:layout_constraintTop_toTopOf="parent" />
<!-- <ImageView-->
<!-- android:id="@+id/effective_warnings_card_icon"-->
<!-- android:layout_width="48dp"-->
<!-- android:layout_height="48dp"-->
<!-- android:layout_marginStart="@dimen/margin_default"-->
<!-- app:srcCompat="@drawable/account_unavailable_image"-->
<!-- android:importantForAccessibility="no"-->
<!-- android:focusable="false"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- tools:src="@tools:sample/avatars"-->
<!-- />-->
<!-- <TextView-->
<!-- android:id="@+id/effective_warnings_card_text"-->
<!-- style="@style/TextAppearance.TSBApp20.Body.Regular"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!--android:text="afafafaffafa"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toEndOf="@+id/effective_warnings_card_icon"-->
<!-- app:layout_constraintBottom_toBottomOf="@+id/effective_warnings_card_icon"-->
<!-- app:layout_constraintTop_toTopOf="@+id/effective_warnings_card_icon"-->
<!-- />-->
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
-
分享您想要实现的 UI。
-
@MehulKabaria 这是在其他地方使用的卡片布局的一部分,因此无法分享整个内容。基本上我需要并排的图像和文本,比如图像右侧的文本,整体在卡片视图中。并在适配器中使用它。
标签: android android-constraintlayout