Android GridLayout API 21

I am trying to execute something like this:

enter image description here

Currently, I manually set the tile width to half the width of the screen. This works well, but it makes it difficult to add separators between the plates (as shown in the screenshot). Fortunately, it looks like API 21 now has weight support in GridLayout , provided here for your convenience:

API 21, GridLayout . , , , . , , , , . , , . , , .

. , . , . , , , .

, , . , , .

, GridLayout , . , GridLayout , . GridLayout , , - .

, GridLayout , :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:columnCount="2">
        <TextView android:layout_width="wrap_content" android:layout_gravity="fill_horizontal" android:text="Hello" android:layout_columnWeight="1" />
        <TextView android:layout_width="wrap_content" android:layout_gravity="fill_horizontal" android:text="Hello" android:layout_columnWeight="1" />
        <TextView android:layout_width="wrap_content" android:layout_gravity="fill_horizontal" android:text="Hello" android:layout_columnWeight="1" />
        <TextView android:layout_width="wrap_content" android:layout_gravity="fill_horizontal" android:text="Hello" android:layout_columnWeight="1" />
        <TextView android:layout_width="wrap_content" android:layout_gravity="fill_horizontal" android:text="Hello" android:layout_columnWeight="1" />
    </GridLayout>
</RelativeLayout>

, , , . , :

enter image description here

, . - ? , GridLayout?

, 0 , (TextView ). GridLayout?

+4
2

android:layout_width="0dp" GridLayout ( layout_width="0dp" .)

, , , .

, .

+5

, ,

  <GridLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"        
    android:columnCount="2" > 

    <Button
        android:layout_column="0"
        android:layout_gravity="fill"
        android:layout_row="0"
        android:layout_columnWeight="1"
        android:text="c0 | r0" />

   <Button
        android:layout_column="1"
        android:layout_gravity="fill"
        android:layout_row="0"
         android:layout_columnWeight="1"
        android:text="c1 | r0" />

   <Button
        android:layout_column="1"
        android:layout_gravity="fill"
        android:layout_row="3"
        android:layout_columnWeight="1"
        android:text="c1 | r3" />

   <Button
        android:layout_column="0"
        android:layout_gravity="fill"
        android:layout_row="1"
        android:layout_columnWeight="1"
        android:text="c0 | r1" />

</GridLayout>

, gridlayout ?

( ).. , .

gridlayout, 2 , .. .. , , column empty.its .

,

+2

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


All Articles