线性布局的计算器应用程序 [英] Linear Layout for a calculator app

查看:141
本文介绍了线性布局的计算器应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的线性布局的最后一排的一个问题。我想要的0是大小相同的,因为所有其他号码,然后该行中的其他4个按钮是像下面(这是使用绝对布局):

I am having a problem on the last row of my linear layout. I want the 0 to be the same size as all the other numbers, and then the other 4 buttons in that row to be like below (this is using Absolute Layout):

正确看我,所以这是一个tinypic不能发表图片

Correct Look I could not post images so this is a tinypic

但是,使用线性布局,这就是我需要使用,所以它看起来在所有屏幕尺寸正确的,我不能让最后一排看的权利。问题是图像,他们不会让我正确缩放按钮。我敢肯定,我可以通过缩小图像修复它,但我希望他们留下来的大小,只是使按钮更薄。有谁知道该怎么做?重量似乎不工作。

But using Linear Layout, which is what I need to use so it looks correct on all screen sizes, I cannot get the last row to look right. The problem is the images, they do not let me scale the buttons correctly. I'm sure I could fix it by scaling down the images, but I want them to stay that size, and just make the buttons thinner. Does anyone know how to do that? Weights don't seem to work.

需要改变所以这是一个tinypic我不能发表图片

Needs changing I could not post images so this is a tinypic

下面是我的XML文件:

Here is my xml file:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1">

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

    <TextView
        android:id="@+id/widget40"
        android:gravity="right"
        android:textSize="40sp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1">

    <Button
        android:id="@+id/widget34"
        android:text="7"
        android:gravity="center_vertical|center_horizontal" 
        android:layout_width="wrap_content"
        android:textSize="35sp"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/widget35"
        android:gravity="center_vertical|center_horizontal" 
        android:text="8"
        android:textSize="35sp"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/widget37"
        android:gravity="center_vertical|center_horizontal" 
        android:text="9"
        android:textSize="35sp"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>

</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1">

    <Button
        android:id="@+id/widget31"
        android:gravity="center_vertical|center_horizontal" 
        android:text="4"
        android:layout_width="wrap_content"
        android:textSize="35sp"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/widget32"
        android:gravity="center_vertical|center_horizontal" 
        android:text="5"
        android:textSize="35sp"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/widget33"
        android:gravity="center_vertical|center_horizontal" 
        android:text="6"
        android:textSize="35sp"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>

</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1">

    <Button
        android:id="@+id/widget28"
        android:gravity="center_vertical|center_horizontal" 
        android:text="1"
        android:textSize="35sp"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/widget29"
        android:gravity="center_vertical|center_horizontal" 
        android:text="2"
        android:layout_width="wrap_content"
        android:textSize="35sp"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/widget30"
        android:gravity="center_vertical|center_horizontal" 
        android:text="3"
        android:textSize="35sp"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>

</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1">

    <Button
        android:id="@+id/widget38"
        android:gravity="center_vertical|center_horizontal" 
        android:text="0"
        android:layout_width="wrap_content"
        android:textSize="35sp"
        android:layout_height="fill_parent"
        android:layout_weight="30"/>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="30">

        <Button
            android:id="@+id/widget72"
                android:gravity="center_vertical|center_horizontal" 
                android:text="R"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:textSize="35sp"
                android:layout_weight="1"/>

        <Button
                android:id="@+id/widget73"
                android:gravity="center_vertical|center_horizontal" 
                android:text="Z"
                android:layout_width="wrap_content"
                android:textSize="35sp"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>

            <Button
                android:id="@+id/widget70"
                android:gravity="center_vertical|center_horizontal" 
                android:layout_width="wrap_content"
                android:drawableBottom="@drawable/back"
                android:textSize="35sp"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>

            <Button
                android:id="@+id/widget39"
                android:gravity="center_vertical|center_horizontal" 
                android:textSize="35sp"
                android:drawableBottom="@drawable/search"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>

     </LinearLayout>

</LinearLayout>

推荐答案

最后的LinearLayout包含两个对象:巴顿和的LinearLayout。
你希望它可分为:对按钮1单元和2单元LL。所以,你应该设置按钮layout_weight =1和LL layout_weight =2。还设置layout_width =FILL_PARENT(或0dp - 应采取行动一样体重会提供适当的重量)

Last LinearLayout consists of two objects: Button and LinearLayout. You want it to be divided: 1 unit for button and 2 units for LL. So you should set button layout_weight="1" and LL layout_weight="2". Set also layout_width="fill_parent" (or "0dp" - should act the same as weight will provide proper weight).

您也可以把R和Z一LL和箭头,搜索第二LL。然后,你将有三个对象,因此把layout_weight =1,他们每个人相同的大小。

You can also put "R" and "Z" to one LL and "arrow", "search" to second LL. Then you will have three objects the same size so put layout_weight="1" to each of them.

下面是关于使用重量参数文章:的http://开发商。 android.com/resources/articles/layout-tricks-efficiency.html

Here is article about using weight parameter: http://developer.android.com/resources/articles/layout-tricks-efficiency.html

这篇关于线性布局的计算器应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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