1 year ago

#358636

test-img

Gaurav Dureja

How to set textview fits with screen in Constraint Layout

How to set textviews fit with the screen in ConstraintLayout. I need to set textviews with any device auto adjustable. How to set all childsview within the parent ConstraintLayout. The third child view is going outside the screen. Is there any way that child views adjust with the parent ConstraintLayout automatically with any device. Please help

Here is the code:

<androidx.constraintlayout.widget.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingTop="20dp"
                        android:paddingBottom="20dp">

                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:id="@+id/phoneLayout"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="15dp"
                            app:layout_constraintLeft_toLeftOf="parent"
                            app:layout_constraintRight_toLeftOf="@id/updateProfile"
                            app:layout_constraintTop_toTopOf="parent">

                            <ImageView
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintTop_toTopOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                android:id="@+id/imgPhoneVerify"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                app:srcCompat="@drawable/ic_verified"
                                tools:ignore="ContentDescription" />

                            <TextView
                                app:layout_constraintHorizontal_bias="0.0"
                                app:layout_constraintHorizontal_chainStyle="packed"
                                android:lines="2"
                                android:maxLines="2"
                                app:layout_constraintWidth_default="wrap"
                                app:layout_constraintTop_toTopOf="parent"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintStart_toEndOf="@id/imgPhoneVerify"
                                android:id="@+id/textview"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="5dp"
                                android:layout_toEndOf="@+id/imgPhoneVerify"
                                android:includeFontPadding="false"
                                android:text="Phone Verified"
                                android:textColor="#757575"
                                android:textSize="15sp"
                                tools:ignore="HardcodedText" />

                        </androidx.constraintlayout.widget.ConstraintLayout>

                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:id="@+id/updateProfile"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            app:layout_constraintLeft_toRightOf="@id/phoneLayout"
                            app:layout_constraintRight_toLeftOf="@id/getVerified"
                            app:layout_constraintTop_toTopOf="parent">

                                <ImageView
                                    app:layout_constraintStart_toStartOf="parent"
                                    app:layout_constraintTop_toTopOf="parent"
                                    app:layout_constraintBottom_toBottomOf="parent"
                                    android:id="@+id/imgProfile"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    app:srcCompat="@drawable/ic_verified"
                                    tools:ignore="ContentDescription" />

                            <TextView
                                app:layout_constraintHorizontal_bias="0.0"
                                app:layout_constraintHorizontal_chainStyle="packed"
                                android:lines="2"
                                android:maxLines="2"
                                app:layout_constraintWidth_default="wrap"
                                app:layout_constraintTop_toTopOf="parent"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintStart_toEndOf="@id/imgProfile"
                                android:id="@+id/tvProfileComplete"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_centerInParent="true"
                                android:layout_marginStart="5dp"
                                android:breakStrategy="simple"
                                android:text="Profile Complete"
                                android:textColor="#757575"
                                android:textSize="15sp"
                                tools:ignore="HardcodedText"
                                tools:targetApi="m" />

                        </androidx.constraintlayout.widget.ConstraintLayout>

                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:id="@+id/getVerified"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            app:layout_constraintLeft_toRightOf="@id/updateProfile"
                            app:layout_constraintRight_toRightOf="parent"
                            app:layout_constraintTop_toTopOf="parent">

                            <ImageView
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toTopOf="parent"
                                app:layout_constraintBottom_toBottomOf="parent"
                                android:id="@+id/imgProfileVerify"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                app:srcCompat="@drawable/ic_verify_pending"
                                tools:ignore="ContentDescription" />

                            <TextView
                                app:layout_constraintHorizontal_bias="0.0"
                                app:layout_constraintHorizontal_chainStyle="packed"
                                android:lines="2"
                                android:maxLines="2"
                                app:layout_constraintWidth_default="wrap"
                                app:layout_constraintTop_toTopOf="parent"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toEndOf="@id/imgProfileVerify"
                                android:id="@+id/tvProfileVerify"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_centerHorizontal="true"
                                android:layout_marginStart="5dp"
                                android:layout_toEndOf="@+id/imgProfileVerify"
                                android:text="Get Verified"
                                android:textColor="#757575"
                                android:textSize="15sp"
                                tools:ignore="HardcodedText" />

                        </androidx.constraintlayout.widget.ConstraintLayout>

                    </androidx.constraintlayout.widget.ConstraintLayout>

It is going outsize screen:

enter image description here

java

android

android-constraintlayout

0 Answers

Your Answer

Accepted video resources