哪种布局更好用? [英] Which Layout is better to use?

查看:68
本文介绍了哪种布局更好用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我必须使用计算器. 计算器中的其他"按钮应如下图所示.

In My Application i have to use the Calculator. The Different Button in Calculator should be like below image.

那么,什么样的布局才是更好的选择呢? 我认为gridView很好,但是在考虑"0"按钮和"C"按钮下方的按钮时,我不知道如何将其设置到gridview中. 因此,Anybudy告诉我哪种是设置这种布局的最佳方法? 最近,我已经使用相对布局来设置此布局. 请帮助我.如果GridView对此很满意,请告诉我该使用两个按钮该怎么做:一个是"0"按钮,第二个是在左侧"按钮下方的Button.

So, What should be better to implement such type of the Layout ? I think gridView is good, but while thinking about the "0" Button and the Button below "C" button, I dont know how to set it in to the gridview. So Anybudy tell me which one is the Best way to set this type of layout ? recently i have use the relative layout to set this layout. Please help me regarding this. and if the GridView is nice with this then tell me what should i have to do with that two buttons: one is "0" button and second is the Button that is below thee Button of "left errow".

要使用RelativeLayout的代码:

Code to have Use the RelativeLayout:

<RelativeLayout android:id="@+id/calculationButtonLayout"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_below="@+id/totalAmount" android:layout_margin="10dp">

        <RelativeLayout android:id="@+id/linear_layout" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:orientation="vertical"
            android:layout_centerInParent="true" android:gravity="center_horizontal">

            <!-- First row Start -->

                <Button android:id="@+id/sevenNumber" 
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="7" android:textColor="#ffffff" android:textSize="22dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                    android:background="@drawable/selector_button"/>

                <Button android:id="@+id/eightNumber" android:layout_toRightOf="@+id/sevenNumber"
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="8" android:textColor="#ffffff" android:textSize="22dp"
                    android:background="@drawable/selector_button"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"/>

                <Button android:id="@+id/nineNumber" android:layout_toRightOf="@+id/eightNumber"
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="9" android:textColor="#ffffff" android:textSize="22dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                    android:background="@drawable/selector_button"/>    

                <Button android:id="@+id/acButton" android:layout_toRightOf="@+id/nineNumber"
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="AC" android:textColor="#ffffff" android:textSize="22dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                    android:background="@drawable/brown_button"/>

            <!-- First row Finish -->

            <!-- Second row Start -->

                <Button android:id="@+id/fourNumber" android:layout_below="@+id/sevenNumber" 
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="4" android:textColor="#ffffff" android:textSize="22dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                    android:background="@drawable/selector_button"/>

                <Button android:id="@+id/fiveNumber" android:layout_toRightOf="@+id/fourNumber" android:layout_below="@+id/eightNumber"
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="5" android:textColor="#ffffff" android:textSize="22dp"
                    android:background="@drawable/selector_button"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"/>

                <Button android:id="@+id/sixNumber" android:layout_toRightOf="@+id/fiveNumber" android:layout_below="@+id/nineNumber"
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="6" android:textColor="#ffffff" android:textSize="22dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                    android:background="@drawable/selector_button"/>    

                <Button android:id="@+id/clearButton" android:layout_toRightOf="@+id/sixNumber" android:layout_below="@+id/acButton"
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="C" android:textColor="#ffffff" android:textSize="22dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                    android:background="@drawable/brown_button"/>

            <!-- Second row finish -->

            <!-- Third row Start -->


                <Button android:id="@+id/oneNumber" android:layout_below="@+id/fourNumber" 
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="1" android:textColor="#ffffff" android:textSize="22dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                    android:background="@drawable/selector_button"/>

                <Button android:id="@+id/twoNumber" android:layout_toRightOf="@+id/oneNumber" android:layout_below="@+id/fiveNumber"
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="2" android:textColor="#ffffff" android:textSize="22dp"
                    android:background="@drawable/selector_button"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"/>

                <Button android:id="@+id/threeNumber" android:layout_toRightOf="@+id/twoNumber" android:layout_below="@+id/sixNumber"
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="3" android:textColor="#ffffff" android:textSize="22dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                    android:background="@drawable/selector_button"/>    



            <!-- Third row finish -->

            <!-- Fourth row Start -->


                <Button android:id="@+id/zeroNumber" android:layout_below="@+id/oneNumber"
                    android:layout_height="50dp" android:layout_width="110dp"
                    android:text="0" android:textColor="#ffffff" android:textSize="22dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                    android:background="@drawable/selector_button"/>

                <Button android:id="@+id/dotNumber" android:layout_toRightOf="@+id/zeroNumber" android:layout_below="@+id/threeNumber"
                    android:layout_height="50dp" android:layout_width="50dp"
                    android:text="." android:textColor="#ffffff" android:textSize="22dp"
                    android:background="@drawable/selector_button"
                    android:layout_marginTop="5dp" android:layout_marginBottom="5dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"/>

                <Button android:id="@+id/doNothing" android:layout_toRightOf="@+id/threeNumber" android:layout_height="wrap_content" android:layout_width="50dp"
                    android:textColor="#ffffff" android:textSize="22dp"
                    android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
                    android:background="@drawable/do_nothing_button" android:layout_alignBottom="@+id/dotNumber" android:layout_alignTop="@+id/threeNumber"/>

            <!-- Third row finish -->

        </RelativeLayout>

    </RelativeLayout>

此布局后得到的图像是:

The Image that i got after this Layout is:

在此图像中,键盘不适用于整个中间窗口.我也想将其放入窗口"中. 那我该怎么办呢?

In this Image the Keypad is not fit to the Whole Middle Window. I want to fit it in to the Window also. So What should i have to do for it ?

推荐答案

您应该使用Relative layout,因为它会根据不同的分辨率屏幕进行调整.

You should use Relative layout as it will adjust itself with different resolution screens.

这篇关于哪种布局更好用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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