-1

I have a parent ConstraintLayout in my fragment.xml:

<?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="400dp"
    android:maxHeight="400dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/colorPopupBackground"
    android:fadeScrollbars="false"
    android:id="@+id/profile_layout"
    android:elevation="1dp">

as you can see i've set a maxHeight and constrained it on every side - so you would think it should centre vertically on the screen. However the ConstraintLayout sits on the top vertically.

Any idea?

Zorgan
  • 8,227
  • 23
  • 106
  • 207

1 Answers1

0

Just remove bottom constraint because when you set both side constraint and set custom width then it will be center of both constraint, SO update your code like bellow

<?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="400dp"
    android:maxHeight="400dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"

    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/colorPopupBackground"
    android:fadeScrollbars="false"
    android:id="@+id/profile_layout"
    android:elevation="1dp">
Dhaval Solanki
  • 4,589
  • 1
  • 23
  • 39