You need to use nested constraint layout or you can use any other ViewGroup like RelativeLayout, LinearLayout etc according to your needs.
In your case, As you View height should be according to the content so you can not fix it height.
Suggested solutions is:
<androidx.constraintlayout.widget.ConstraintLayout ...>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="40dp"
android:background="@drawable/display_result">
<TextView
android:id="@+id/error_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="12dp"
android:fontFamily="@font/poppins_medium"
android:text="@string/error_msg"
android:textAlignment="center"
android:textColor="@color/white"
app:layout_constraintBottom_toTopOf="@+id/error_try_again"
app:layout_constraintEnd_toEndOf="@+id/error_view"
app:layout_constraintStart_toStartOf="@+id/error_view"
app:layout_constraintTop_toTopOf="@+id/error_view" />
<Button
android:id="@+id/error_try_again"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="24dp"
android:background="@drawable/primary_button"
android:text="@string/try_again"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/error_view"
app:layout_constraintEnd_toEndOf="@+id/error_view"
app:layout_constraintStart_toStartOf="@+id/error_view" />
</constraint>
</androidx.constraintlayout.widget.ConstraintLayout>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…