How to position views using percent for top / left container?

I hope to place positions in the parent view using percentages similar to what is possible with absolute positioning in CSS. In my scenario, I will have a variable and unpredictable number of views to be positioned this way.

Here is an example representing 3 TextViews inside a square with the following positions:

1: Top 55%, Left 29%
2: Top 77%, left 58%
3: Top 54%, Left 43%

Percent Views

? , ? , ? , , ?

+4
2

ConstraintLayout https://developer.android.com/training/constraint-layout/index.html

, , , . :

<android.support.constraint.ConstraintLayout
    android:id="@+id/constraint"
    android:layout_width="match_parent"
    android:layout_height="200dp">

    <TextView
        android:id="@+id/edition_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.33"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.33"
        android:background="@android:color/holo_purple"
        android:text="text"/>

</android.support.constraint.ConstraintLayout>

, (Textview) , . , , .

:

enter image description here

, . : http://www.zoftino.com/adding-views-&-constraints-to-android-constraint-layout-programmatically

0

X Y, Android. p >

enter image description here

, !

0

Source: https://habr.com/ru/post/1693718/


All Articles