Android开发经验谈Android开发

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

2018-10-18  本文已影响76人  微胖三金

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="="/>

上一篇 下一篇

猜你喜欢

热点阅读