androidx / constraintlayout

ConstraintLayout is an Android layout component which allows you to position and size widgets in a flexible way
Apache License 2.0
1.07k stars 176 forks source link

initial code for the Grid helper #601

Closed jswong65 closed 2 years ago

jswong65 commented 2 years ago

The initial PR for the Grid helper. This helper is introduced to help build a grid patten. There are still improvements need to be made (e.g, handle RTL, check if the attributes are valid)

Please review the Grid.java. For most of the other codes, they are copied from MotionLayoutExperiment. Sample usage:

<androidx.constraintlayout.helper.widget.Grid
   android:id="@+id/grid"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   app:grid_rows="4"
   app:grid_columns="4"
   app:grid_spans="button5:12#1x3"
   app:grid_orientation="horizontal"
   app:grid_skips="0:2x2,6:1x1"
   app:constraint_referenced_ids="button, button2, button3, button4"
   app:grid_horizontalGaps="10"
   app:grid_verticalGaps="10"/>

image

The format of skip: index:row_spanxcol_span

index - the index of the starting position row_span - the number of rows to span col_span- the number of columns to span

The format of span: viewId:index#row_spanxcol_span-gravity

viewID - the id of a view in the constraint_referenced_ids list index - the index of the starting position row_span - the number of rows to span col_span- the number of columns to span gravity (optional) - letters t, l, b, r, s ,e = top, left, bottom, right, start, end. Two letters could be used together (e.g., tl, br, etc.)

Examples are also included in this PR (activity_main.xml, calculator.xml, and dialer.xml)

image image image