Skip to content Skip to sidebar Skip to footer

Constraint Layout With Percentage Not Working As Expected

I would make a view that has 70% width and align to the right of its parent using constraint layout as follow
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"><android.support.constraint.Guidelineandroid:id="@+id/guideline"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical"app:layout_constraintGuide_percent="0.3" /><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:text="Hello text"app:layout_constraintLeft_toRightOf="@id/guideline"app:layout_constraintRight_toRightOf="parent" /></android.support.constraint.ConstraintLayout>

Output:

enter image description here

Also note that I changed the ConstraintLayout height to match_parent so that the guideline was visible in the output. You can change it back to wrap_content.

Post a Comment for "Constraint Layout With Percentage Not Working As Expected"