Center horizontally group of elements inside the ConstraintLayout

Advertisements I have to place three components inside the constraint layout: image, and on the right of the image two textviews one above other. Both text views are centered along the image. They all together should be centered horizontally inside. There is my code : <com.google.android.material.card.MaterialCardView android:id="@+id/downloadPlan" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" android:layout_marginBottom="16dp" android:clickable="true" android:focusable="true"… Read More Center horizontally group of elements inside the ConstraintLayout

The app:layout_constraintVertical_chainStyle="spread_inside" or any of the options – packed, spread – has not effect; why?

Advertisements <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android&quot; xmlns:app="http://schemas.android.com/apk/res-auto&quot; xmlns:tools="http://schemas.android.com/tools&quot; android:layout_width="match_parent" android:layout_height="match_parent" app:layout_constraintVertical_chainStyle="spread_inside"> <androidx.appcompat.widget.AppCompatButton android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toTopOf="@+id/button2" app:layout_constraintTop_toTopOf="parent"/> <androidx.appcompat.widget.AppCompatButton android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 2" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/button1" app:layout_constraintBottom_toTopOf="@id/button3"/> <androidx.appcompat.widget.AppCompatButton android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 3" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/button2"/> </androidx.constraintlayout.widget.ConstraintLayout> In the provided code, the attribute app:layout_constraintVertical_chainStyle="spread_inside" is set on the parent ConstraintLayout. This… Read More The app:layout_constraintVertical_chainStyle="spread_inside" or any of the options – packed, spread – has not effect; why?

ConstraintLayout how to align to center of screen and not to overlap uneven side buttons

Advertisements I have a design request to make a text be the center of the screen but not to overlap buttons on the sides. those buttons might appear or not. This is the design: The problem is when the text is long, this bad thing happens: But I want it to be like this: >Solution… Read More ConstraintLayout how to align to center of screen and not to overlap uneven side buttons

Why TextView's margin not working in ConstraintLayout

Advertisements My id/ambient_check_text’s marginStart/marginEnd not working, I tested in real device. It looks like below: layout: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android&quot; xmlns:app="http://schemas.android.com/apk/res-auto&quot; xmlns:tools="http://schemas.android.com/tools&quot; android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/ambient_title_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="20dp" android:layout_marginTop="10dp" android:layout_marginEnd="16dp" android:layout_weight="1" android:alpha="0.80" android:drawableEnd="@drawable/vip_detail_activity_ic_pro" android:singleLine="true" android:text="@string/ambient_detail_title" android:textColor="@color/white" android:textSize="16sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <util.TopCropImageView android:id="@+id/ambient_permission_bg" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="10dp" android:layout_marginTop="16dp" android:layout_marginEnd="10dp" android:adjustViewBounds="true" android:scaleType="fitXY" android:src="@drawable/ambient_detail_permission_bg" app:layout_constraintTop_toBottomOf="@id/ambient_title_text" tools:ignore="ContentDescription" />… Read More Why TextView's margin not working in ConstraintLayout

When extend AppCompatEditText it overlap on TextView – Android

Advertisements I have bellow layout: <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android&quot; xmlns:app="http://schemas.android.com/apk/res-auto&quot; xmlns:tools="http://schemas.android.com/tools&quot; android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context=".activities.completion_information_activity.CompletionInformationActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appBarCompletionInformation" android:layout_width="match_parent" android:layout_height="240dp" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout android:id="@+id/toolbarLayoutCompletionInformation" android:layout_width="match_parent" android:layout_height="match_parent" android:minHeight="60dp" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:toolbarId="@+id/toolbarCompletionInformation"> <androidx.appcompat.widget.Toolbar android:id="@+id/toolbarCompletionInformation" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:contentInsetStart="0dp" android:contentInsetLeft="0dp" android:contentInsetEnd="0dp" android:contentInsetRight="0dp" app:contentInsetEnd="0dp" app:contentInsetLeft="0dp" app:contentInsetRight="0dp" app:contentInsetStart="0dp" app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay" app:title="SSADSDWQEWQ"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center"> <ImageButton android:id="@+id/imgBackCompletionInformation" android:layout_width="50dp" android:layout_height="match_parent" android:layout_centerVertical="true" android:background="@null" android:src="@drawable/ic_baseline_arrow_back_24"… Read More When extend AppCompatEditText it overlap on TextView – Android

why preview showing different ui and real screen different in constrainlayout

Advertisements I am developing new android app but when I am trying to implement constrainlayout in preview window it is showing different but in real device showing different below my layout <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android&quot; xmlns:app="http://schemas.android.com/apk/res-auto&quot; xmlns:tools="http://schemas.android.com/tools&quot; android:layout_width="match_parent" android:layout_height="match_parent" android:background="#451C80" tools:context=".SetPasswordFragment"> <TextView android:id="@+id/getStarted" style="@style/password" android:layout_width="178dp" android:layout_height="wrap_content" android:layout_marginTop="72dp" android:layout_marginEnd="150dp" android:gravity="center" android:text="@string/password" android:textAppearance="@style/password" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" />… Read More why preview showing different ui and real screen different in constrainlayout

Android ConstraintLayout: set one element in the center of another one

Advertisements I’m using ConstraintLayout in order to create activity view There is a code snippet: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android&quot; xmlns:tools="http://schemas.android.com/tools&quot; xmlns:app="http://schemas.android.com/apk/res-auto&quot; android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="bottom" android:orientation="vertical" tools:context=".presentation.screens.registration.RegistrationActivity"> <LinearLayout>…</LinearLayout> <Button android:id="@+id/login_next_btn" app:layout_constraintRight_toRightOf="parent" app:layout_constraintBottom_toBottomOf="parent" android:background="@drawable/button_green_disabled" android:layout_width="match_parent" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" android:layout_marginBottom="24dp" android:text="@string/next" android:textColor="@color/font_white" android:textSize="16sp" android:layout_height="48dp" android:enabled="false" android:onClick="onNextClick"/> <ImageView android:id="@+id/loader_image" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintBottom_toBottomOf="@+id/login_next_btn" android:src="@drawable/ic_loader"/> </androidx.constraintlayout.widget.ConstraintLayout> The question is:… Read More Android ConstraintLayout: set one element in the center of another one

Create Views Within ConstraintLayout programatically

Advertisements I want to create a simple layout with 3 rows of the TextView elements. The first and the last row contain just one text view each and the middle row contains two adjacent text views. Link to the Image Here is the xml for generating the views <TextView android:id="@+id/textView" android:layout_width="0dp" android:layout_height="0dp" android:text="TextView" app:layout_constraintBottom_toTopOf="@+id/textView2" app:layout_constraintEnd_toEndOf="parent"… Read More Create Views Within ConstraintLayout programatically

ConstraintLayout: Second view snaps to parent instead of bottom of custom view

Advertisements I have two views in a constraint layout, one custom and one a standard ImageView. I want to place the ImageView below the custom view. I’m setting app:layout_constraintTop_toBottomOf on the ImageView attach it to the bottom of the custom view. However, my ImageView snaps to the top of the parent layout, rather than the… Read More ConstraintLayout: Second view snaps to parent instead of bottom of custom view