为什么我无法创建2个按钮来填充GridLayout上的所有单元格?

时间:2015-11-13 07:53:14

标签: android android-layout

我想创建一些包含2个按钮的布局,该按钮填充所有布局。

我想创建一个布局 - 并在此布局上添加两个按钮,这些按钮将填充所有布局空间(左侧的按钮1和右侧的按钮2)

我无法理解为什么我在gridLayout上定义的列不会填充所有布局。

我该怎么办? 我需要改变什么才能拥有2个控制器来填充所有网格?

代码和截图:

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

我从此代码中获得的屏幕截图:

enter image description here

我想要的是:

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试将此行添加到按钮中

android:layout_columnWeight="1"

我希望能帮到你