码迷,mamicode.com
首页 > 其他好文 > 详细

实现一个计算器的例子

时间:2020-01-23 21:16:47      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:bsp   mat   com   view   一个   range   layout   and   oid   

layout

absolute_layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:orientation="horizontal">
    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:background="@drawable/shape_rectangle"
        android:text="C"
        android:textSize="30sp"/>
    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:background="@drawable/shape_rectangle"
        android:text="+/-"
        android:textSize="30sp"/>
    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:background="@drawable/shape_rectangle"
        android:text="%"
        android:textSize="30sp"/>
    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:background="@drawable/shape_rectangle_orange"
        android:text="÷"
        android:textSize="30sp"/>
</LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle"
            android:text="7"
            android:textSize="30sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle"
            android:text="8"
            android:textSize="30sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle"
            android:text="9"
            android:textSize="30sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle_orange"
            android:text="×"
            android:textSize="30sp"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle"
            android:text="4"
            android:textSize="30sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle"
            android:text="5"
            android:textSize="30sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle"
            android:text="6"
            android:textSize="30sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle_orange"
            android:text="-"
            android:textSize="30sp"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle"
            android:text="1"
            android:textSize="30sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle"
            android:text="2"
            android:textSize="30sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="3"
            android:background="@drawable/shape_rectangle"
            android:textSize="30sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:background="@drawable/shape_rectangle_orange"
            android:text="+"
            android:textSize="30sp"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:gravity="center_vertical"
            android:paddingLeft="40dp"
            android:text="0"
            android:background="@drawable/shape_rectangle"
            android:textSize="30sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="."
            android:background="@drawable/shape_rectangle"
            android:textSize="30sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="="
            android:background="@drawable/shape_rectangle"
            android:textSize="30sp"/>

    </LinearLayout>
</LinearLayout>

 

drawable

shape_recangle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
       android:shape="rectangle">
    <solid android:color="#ffffff"/>
    <stroke android:color="#333333" android:width="1dp"/>
</shape>

shape_recangle_orange.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
       android:shape="rectangle">
    <solid android:color="#e47f26"/>
    <stroke android:color="#333333" android:width="1dp"/>
</shape>

技术图片

实现一个计算器的例子

标签:bsp   mat   com   view   一个   range   layout   and   oid   

原文地址:https://www.cnblogs.com/yeyueweiliang/p/12231142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!