Yanshof
Yanshof

Reputation: 9926

Why i can't create 2 buttons that fill all the cell on GridLayout ?

I want to create some layout that contain 2 button that fills all the layout.

I want to create a layout - and on this layout to add two buttons that will fill all the layout space ( button 1 on the left side - and button 2 on the right side )

I can't understand why the column that i define on the gridLayout are not fill all the layout.

How can i do it ? What i need to change to have 2 controls that fill all the grid ?

The code and screenshot:

<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     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"
     app:layout_behavior="@string/appbar_scrolling_view_behavior"
     tools:showIn="@layout/activity_main"
     tools:context=".MainActivity"
     android:orientation="horizontal">

<GridLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:columnCount="2"
    android:rowCount="1">

    <Button
        android:text="Start"
        android:layout_column="0"
        android:background="@android:drawable/ic_media_play" />

    <Button
        android:text="End"
        android:layout_column="1"
        android:background="@android:drawable/ic_media_pause" />

</GridLayout>

Screenshot of what i got from this code:

enter image description here

What i want to have is this:

enter image description here

Upvotes: 0

Views: 50

Answers (1)

Hugo Mallet
Hugo Mallet

Reputation: 210

Try to add this line into your buttons

android:layout_columnWeight="1"

I hope that help you

Upvotes: 1

Related Questions