Android GridLayout API 21

霸气de小男生 提交于 2019-11-29 07:18:35
machao

Just add android:layout_width="0dp" to every child of the GridLayout (any child without layout_width="0dp" will break the weight layout.)

Make sure there is no child view has a bigger width size than average width size if you have child view with specify width size.

Hope it will help u.

try this, i will edit it very soon, want to try myself and see

  <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>

the text on the buttons explains how gridlayout works pretty cool right?

You specify the number of columns for a row and you place your widgets in their respective position (Column Number and Row Number).. placed the positions in the text to reflect it..

actually never took the time with gridlayout, i had to play with eclipse for 2 minutes to get it.. so column and row.. you can play with them actually, i just did and had one column and the other column empty.its in my example.

hope it helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!