WRAP_CONTENT : Enforcing Constraints

Kullandığınız bileşen WRAP_CONTENT olarak ayarlanmış ve margin değerleri ile sınırlanmış ise bunu istediğiniz zaman iptal edip, istediğiniz zaman ekleme yapabilirsiniz.

Bu özellikleri bize true ve false değerleri alabilen aşağıdaki layout_constrainedWidth ve layout_constrainedHeight parametreleri sağlıyor.

app:layout_constrainedWidth=”true|false” app:layout_constrainedHeight=”true|false”

Örneğin aşağıdaki gibi bir bileşenimiz olsun.

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="40dp"
    android:layout_marginEnd="40dp"
    android:layout_marginTop="40dp"
    android:layout_marginBottom="40dp"
    android:ellipsize="none"
    android:text="Test Text Test Text Test TextTest Text Test Text Test Text Test Text Test Text Test Text Test Text Test Text Test Text Test TextTest Text Test Text Test Text Test Text Test Text Test Text Test Text Test Text Test Text Test TextTest Text Test Text Test Text Test Text Test Text Test Text Test Text"
    app:layout_constrainedWidth="true"
    app:layout_constrainedHeight="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

app:layout_constrainedWidth="true" değeri false olarak değiştirilirse,

Bu bileşen sol ve sağ, üst ve alt kısımlarında margin değeri kullanılmıştır. Bu bileşeni çevreleyen ConstraintLayout’ta WRAP_CONTENT width/height değerlerine sahiptir. Bu senaryoya göre örneğin layout_constrainedWidth değerini false verirsek, sınırlandırmalar iptal edilecek (margin değerleri) ve TextView, ConstraintLayout’a birleşik şekilde görüntülenecektir.

Last updated