android - Issues trying to create GridLayout with elements of different size -


i'm trying create static grid-like layout in android i'm using gridlayout instead of gridview.

this layout i'm trying achieve

using code here base. i'm little confused specifying layout_{weight, margin} on every element inside grid, since it's understanding rowspan , colspan parameters should take care of that. not incorrect?

any pointers?

<?xml version="1.0" encoding="utf-8"?> <gridlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/gridlayout1"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:columncount="2"     android:rowcount="2"     tools:context=".mainactivity" >      <android.support.v7.widget.cardview         android:layout_height="wrap_content"         android:layout_width="wrap_content"         android:id="@+id/card_view"         android:layout_column="0"         android:layout_gravity="fill"         android:layout_row="0"         android:layout_columnspan="1">         <button             android:layout_height="wrap_content"             android:layout_width="wrap_content"             android:id="@+id/button3"             android:text="button" />     </android.support.v7.widget.cardview>      <android.support.v7.widget.cardview         android:layout_height="wrap_content"         android:layout_width="wrap_content"         android:id="@+id/card_view1"         android:layout_column="0"         android:layout_gravity="fill"         android:layout_row="1"         android:layout_columnspan="1">         <button             android:layout_height="wrap_content"             android:layout_width="wrap_content"             android:id="@+id/button1"             android:text="button" />     </android.support.v7.widget.cardview>      <android.support.v7.widget.cardview         android:layout_height="wrap_content"         android:layout_width="wrap_content"         android:id="@+id/card_view3"         android:layout_column="1"         android:layout_gravity="fill"         android:layout_row="1">         <button             android:layout_height="wrap_content"             android:layout_width="wrap_content"             android:id="@+id/button2"             android:text="button" />     </android.support.v7.widget.cardview>  </gridlayout> 

you close, try instead:

<gridlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/gridlayout1"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:columncount="2"     android:rowcount="2"     tools:context=".mainactivity" >      <android.support.v7.widget.cardview         android:id="@+id/card_view"         android:layout_column="0"         android:layout_gravity="fill_horizontal"         android:layout_row="0"         android:layout_columnspan="2">         <button             android:layout_height="match_parent"             android:layout_width="match_parent"             android:id="@+id/button3"             android:text="button" />     </android.support.v7.widget.cardview>      <android.support.v7.widget.cardview         android:id="@+id/card_view1"         android:layout_column="0"         android:layout_row="1"         android:layout_columnspan="1"         android:layout_columnweight="1">         <button             android:layout_height="match_parent"             android:layout_width="match_parent"             android:id="@+id/button1"             android:text="button" />     </android.support.v7.widget.cardview>      <android.support.v7.widget.cardview         android:id="@+id/card_view3"         android:layout_column="1"         android:layout_row="1"         android:layout_columnweight="1">         <button             android:layout_height="match_parent"             android:layout_width="match_parent"             android:id="@+id/button2"             android:text="button" />     </android.support.v7.widget.cardview>  </gridlayout> 

you need use layout_gravity="fill_horizontal" first item, stretch whole row. , play layout_columnweight 2nd , 3rd item.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -