Android仿计算器布局代码

来源:互联网 发布:淘宝抢购秒杀怎么抢手机软件 编辑:程序博客网 时间:2024/05/29 21:18
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:stretchColumns="0,1,2,3,4" >

        <TableRow>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="MC" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="MR" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="MS" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="+M" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="-M" />
        </TableRow>

        <TableRow>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="&lt;-" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="CE" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="C" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="+-" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="-/" />
        </TableRow>

        <TableRow>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="7" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="8" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="9" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="/" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="%" />
        </TableRow>

        <TableRow>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="4" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="5" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="6" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="*" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1/x" />
        </TableRow>
    </TableLayout>



    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="98dp"
        android:orientation="vertical" >

        <TableLayout
            android:id="@+id/tl"
            android:layout_width="255dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:stretchColumns="0,1,2,3" >

            <TableRow>

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="3" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="4" />
            </TableRow>

            <TableLayout
                android:layout_width="255dp"
                android:layout_height="wrap_content"
                android:stretchColumns="0,1,2,3" >

                <TableRow>

                    <Button
                        android:layout_width="94dp"
                        android:layout_height="wrap_content"
                        android:text="0" />

                    <Button
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="." />

                    <Button
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="+" />
                </TableRow>
            </TableLayout>
        </TableLayout>
        <Button
            android:layout_toRightOf="@id/tl"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="="/>
    </RelativeLayout>

</LinearLayout>