首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >android网格视图等尺寸单元格

android网格视图等尺寸单元格
EN

Stack Overflow用户
提问于 2016-01-20 04:50:53
回答 2查看 3.4K关注 0票数 3

我正在尝试制作一个用于练习的计时器应用程序,我遇到了一个问题,即网格视图的大小与其他的不同。

这是代码的一部分

代码语言:javascript
运行
复制
 <GridLayout
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/passwordField"
    android:columnCount="3"
    android:rowCount="4"
    android:verticalSpacing="0dp"
    android:horizontalSpacing="0dp"
    android:stretchMode="columnWidth">


    <Button
        android:id="@+id/btnOne"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_gravity="fill_horizontal"
        android:layout_row="0"
        android:onClick="addInput"
        android:text="@string/one" />

    <Button
        android:id="@+id/btnTwo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_gravity="fill_horizontal"
        android:layout_row="0"
        android:onClick="addInput"
        android:text="@string/two" />

    <Button
        android:id="@+id/btnThree"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="2"
        android:layout_gravity="fill_horizontal"
        android:layout_row="0"
        android:onClick="addInput"
        android:text="@string/three" /> </GridLayout>

在此之后还有更多的按钮,但这是我现在需要显示的全部内容,您可以从图像中看到:

它没有相同的单元格大小,其中第三列比其他列大。我该怎么做才能解决这个问题?

我以前有过RelativeLayout,所有的东西都在正确的位置,但是按钮并不是用来填充宽度的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-01-20 05:14:41

layout_columnWeight是缺失的部分。请注意,您还可以简化Button声明:

代码语言:javascript
运行
复制
<GridLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/passwordField"
        android:columnCount="3"
        android:rowCount="4"
        android:verticalSpacing="0dp"
        android:horizontalSpacing="0dp">


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="addInput"
            android:text="@string/one"
            android:layout_columnWeight="1"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:onClick="addInput"
            android:text="@string/two" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:onClick="addInput"
            android:text="@string/three" />

    </GridLayout>
票数 2
EN

Stack Overflow用户

发布于 2016-01-20 04:59:43

将此属性应用于每个按钮xml。

代码语言:javascript
运行
复制
     android:layout_columnWeight="1"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34891810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档