Android线性布局实现计算机界面

1.线性布局实现计算器界面比较简单,主要是布局的嵌套以及layout_weight属性的使用。代码如下所示:

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

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    tools:context="com.example04.xx.relativelayout01.MainActivity">

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:hint="0"/>

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal">

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="1"/>

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="2"/>

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="3"/>

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="/"/>

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal">

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="4"/>

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="5"/>

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="6"/>

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="*"/>

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal">

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="7"/>

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="8"/>

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="9"/>

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="-"/>

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal">

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:orientation="vertical"

            android:layout_weight="3">

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:orientation="horizontal">

                    android:layout_width="0dp"

                    android:layout_height="wrap_content"

                    android:text="0"

                    android:layout_weight="2"/>

                    android:layout_width="0dp"

                    android:layout_height="wrap_content"

                    android:text="."

                    android:layout_weight="1"/>

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:text="+"/>

            android:layout_width="0dp"

            android:layout_height="match_parent"

            android:layout_weight="1">

                android:layout_width="match_parent"

                android:layout_height="match_parent"

                android:text="="/>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容