i tried configure grid layout 2 rows , 2 columns. each element here occupies entire width of screen, while second column outside screen. please suggest doing wrong here.
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colortheme" android:orientation="vertical"> <gridlayout android:id="@+id/moodsgridlayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/textview2" android:columncount="2" android:orientation="vertical" android:rowcount="2"> <imagebutton android:id="@+id/imagebutton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_column="0" android:layout_row="0" app:srccompat="@mipmap/brewtv_logos" /> <imagebutton android:id="@+id/imagebutton2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_column="1" android:layout_row="0" app:srccompat="@mipmap/brewtv_logos" /> <imagebutton android:id="@+id/imagebutton3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_column="0" android:layout_row="1" app:srccompat="@mipmap/brewtv_logos" /> <imagebutton android:id="@+id/imagebutton4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_column="1" android:layout_row="1" app:srccompat="@mipmap/brewtv_logos" /> </gridlayout> </linearlayout>
try this:
for uniform width column , row in gridlayout use:
android:layout_columnweight="1" android:layout_rowweight="1"
use layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/color_white" android:orientation="vertical"> <gridlayout android:id="@+id/moodsgridlayout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/textview2" android:columncount="2" android:orientation="vertical" android:rowcount="2"> <imagebutton android:id="@+id/imagebutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="0" android:layout_columnweight="1" android:layout_row="0" android:layout_rowweight="1" android:src="@mipmap/ic_launcher" /> <imagebutton android:id="@+id/imagebutton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" android:layout_columnweight="1" android:layout_row="0" android:layout_rowweight="1" android:src="@mipmap/ic_launcher" /> <imagebutton android:id="@+id/imagebutton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="0" android:layout_columnweight="1" android:layout_row="1" android:layout_rowweight="1" android:src="@mipmap/ic_launcher" /> <imagebutton android:id="@+id/imagebutton4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" android:layout_columnweight="1" android:layout_row="1" android:layout_rowweight="1" android:src="@mipmap/ic_launcher" /> </gridlayout> </linearlayout>
output:
Comments
Post a Comment