如何跨越同样按钮/垂直布局android系统中? [英] How to equally span buttons/layouts vertically in android?

查看:241
本文介绍了如何跨越同样按钮/垂直布局android系统中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计算器有一布局等,在每行中的4个按钮,具有一定的5行。我用的LinearLayout 创建这些每一行。我设法填补每一行的宽度完全使用的android:layout_weight =1的LinearLayout 每个按钮。但我不知道如何填写这样的垂直空间。后五排有剩余底部为普通XDPI屏幕(的Nexus 4)

I have a layout like in calculator , 4 buttons in each row , with some 5 rows. I created these each row by using LinearLayout. I had managed to fill width of each row completely by using android:layout_weight="1" in each button in LinearLayout. But i don't know how to fill the vertical space in this way. After five rows there's space remaining at the bottom for Normal XDPI screens(Nexus 4)

<LinearLayout
        android:id="@+id/first_row"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/entry">

    <Button
            android:id="@+id/seven"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="7"
            android:textColor="@color/Blue_ICS"
            android:textSize="@dimen/button_text_size"
            />

    <Button
            android:id="@+id/eight"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="8"
            android:textColor="@color/Blue_ICS"

            android:textSize="@dimen/button_text_size"/>

    <Button
            android:id="@+id/nine"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="9"

            android:textColor="@color/Blue_ICS"
            android:textSize="@dimen/button_text_size"/>

    <Button
            android:id="@+id/plus"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="+"
            android:textColor="@color/Blue_ICS"
            android:textSize="@dimen/button_text_size"/>
</LinearLayout>

布局太长,所以我在这里每股收益只有第一排C $ C,其余行相同了。

The layout is too long so i share here code of only first row, remaining rows are same too.

推荐答案

您应该使用 TableLayout ,更换所有你的的TableRow的LinearLayout。属性stretchColumns使您可以用同样宽度的所有列,而不必使用重量。这样,您就可以使用重量来处理的TableRow高度。

You should use a TableLayout, replacing all your LinearLayout for TableRow. The attribute stretchColumns allows you to make all columns with the same width without having to use weight. This way you can use the weight to handle the TableRow height.

在下面的例子中我甚至增加了一些空间(空的LinearLayout)来显示结果,就像一个计算器屏幕。我希望这是你在找什么! (你必须改变IDS)

In the example below I even added some space (empty LinearLayout) to show the results, like a calculator screen. I hope this is what you're looking for! (You'll have to change the ids)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/outerLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
    android:id="@+id/screenLayout"
    android:layout_width="fill_parent"
    android:layout_height="150dp"
    android:orientation="vertical"></LinearLayout>

<TableLayout
    android:id="@+id/myLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/screenLayout"
    android:stretchColumns="*" >

    <TableRow
        android:id="@+id/first_row"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <Button
            android:id="@+id/seven"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="7" />

        <Button
            android:id="@+id/eight"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="8" />

        <Button
            android:id="@+id/nine"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="9" />

        <Button
            android:id="@+id/plus"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="+" />
    </TableRow>

    <TableRow
        android:id="@+id/first_row"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <Button
            android:id="@+id/seven"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="4" />

        <Button
            android:id="@+id/eight"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="5" />

        <Button
            android:id="@+id/nine"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="6" />

        <Button
            android:id="@+id/plus"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="-" />
    </TableRow>

    <TableRow
        android:id="@+id/first_row"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <Button
            android:id="@+id/seven"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="1" />

        <Button
            android:id="@+id/eight"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="2" />

        <Button
            android:id="@+id/nine"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="3" />

        <Button
            android:id="@+id/plus"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="*" />
    </TableRow>

    <TableRow
        android:id="@+id/first_row"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <Button
            android:id="@+id/seven"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="0" />

        <Button
            android:id="@+id/eight"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="," />

        <Button
            android:id="@+id/nine"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="/" />

        <Button
            android:id="@+id/plus"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:text="=" />
    </TableRow>
</TableLayout>

</RelativeLayout>

结果:

这篇关于如何跨越同样按钮/垂直布局android系统中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆