2015-11-13 18 views
0

我想创建一些布局,其中包含2个填充所有布局的按钮。为什么我不能创建2个按钮来填充GridLayout上的所有单元格?

我想创建一个布局 - 并在此布局,以添加两个按钮,将填补所有的布局空间(左侧按钮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

尝试添加此行到您的按钮

android:layout_columnWeight="1" 

我希望能够帮助您

+0

工作!谢谢 – Yanshof

相关问题