I am trying to place text view on the right side of image view. While I am able to do that, I am facing problem when I give match parent to text view. I want the text to cover remaining area, but when I use match parent, it overlaps the image view on the left. Here is my code
<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>
In the added image you can see text covering the image with black layout. How to achieve this ?
CodePudding user response:
You have to set 0dp
to your TextView
.
<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="0dp"
android:layout_height="wrap_content"
android:background="#000000"
android:text="aggfgffh"
app:layout_constraintEnd_toEndOf="parent"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
CodePudding user response:
Remove app:layout_constraintLeft_toRightOf="@ id/effective_warnings_card_icon"
from TextView
Also remove app:layout_constraintEnd_toEndOf="@id/effective_warnings_card_text"
from ImageView
Set 0dp
width to TextView
<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: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="0dp"
android:layout_height="wrap_content"
android:background="#000000"
android:text="aggfgffh"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@ id/effective_warnings_card_icon"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>