'set proper constraint in bottom android
Hey I am working on constraint layout in android. I am trying to fit my text view and image view in same row, and my image is bigger in size.
The problem is I want to give proper constraint. After setting the proper constraint it will look like this.
activity.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:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingTop="12dp"
tools:ignore="RtlSymmetry">
<TextView
android:id="@+id/testName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="blah blah blah" />
<TextView
android:id="@+id/description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginEnd="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/testIcon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/testName"
tools:text="blah blah blah blah blah blah blah blah blah blah blah blah" />
<ImageView
android:id="@+id/testIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image_pills"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/description"
app:layout_constraintTop_toBottomOf="@+id/testName"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>
Can someone guide me How to set proper constraint.
Solution 1:[1]
in the first textview you need to make this changes:
android:layout_height="0dp"
app:layout_constraintEnd_toStartOf="@+id/testIcon"
in the second textview you need to make this changes:
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="@+id/testIcon"
in the imageview you need to remove this line:
app:layout_constraintStart_toEndOf="@+id/description"
app:layout_constraintTop_toBottomOf="@+id/testName"
Here is my sample working code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/dimen_12"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@id/imageview"
app:layout_constraintBottom_toTopOf="@id/textView1"
android:text="blah blah blah"/>
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/textView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/imageview"
app:layout_constraintBottom_toBottomOf="@id/imageview"
android:text="blah blah blah blah blah blah blah blah blah blah blah blah"/>
<ImageView
android:id="@+id/imageview"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | REX |


