zoukankan      html  css  js  c++  java
  • Android开发UI布局之计算机点击效果练习

    一、预计效果

      实现鼠标在计算器按钮上执行点击动作的时候对应按钮有一个加深颜色的效果

    二、源程序代码

    <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">
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:text="C"
                android:textSize="30dp"
                android:background="@drawable/selector_white"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:text="+/-"
                android:textSize="30dp"
                android:gravity="center"
                android:background="@drawable/selector_white"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:text="%"
                android:textSize="30dp"
                android:gravity="center"
                android:background="@drawable/selector_white"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onOrange"
                android:layout_width="0dp"
                android:background="@drawable/selector_orange"
                android:text="÷"
                android:textSize="30dp"
                android:gravity="center"
    
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp">
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:text="1"
                android:textSize="30dp"
                android:gravity="center"
                android:background="@drawable/selector_white"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:text="2"
                android:textSize="30dp"
                android:gravity="center"
                android:background="@drawable/selector_white"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:text="3"
                android:textSize="30dp"
                android:gravity="center"
                android:background="@drawable/selector_white"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onOrange"
                android:layout_width="0dp"
                android:background="@drawable/selector_orange"
                android:text="X"
                android:textSize="30dp"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp">
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:text="4"
                android:textSize="30dp"
                android:gravity="center"
                android:background="@drawable/selector_white"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:background="@drawable/selector_white"
                android:text="5"
                android:textSize="30dp" />
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:text="6"
                android:textSize="30dp"
                android:gravity="center"
                android:background="@drawable/selector_white"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onOrange"
                android:layout_width="0dp"
                android:background="@drawable/selector_orange"
                android:text="--"
                android:textSize="30dp"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp">
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:text="7"
                android:textSize="30dp"
                android:gravity="center"
                android:background="@drawable/selector_white"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:text="8"
                android:textSize="30dp"
                android:gravity="center"
                android:background="@drawable/selector_white"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:text="9"
                android:textSize="30dp"
                android:gravity="center"
                android:background="@drawable/selector_white"
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onOrange"
                android:layout_width="0dp"
                android:background="@drawable/selector_orange"
                android:text="+"
                android:textSize="30dp"
                android:gravity="center"
    
                android:layout_weight="1"
                android:layout_height="match_parent"/>
    
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:orientation="horizontal">
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:layout_weight="2"
                android:text="0"
                android:textSize="30sp"
                android:paddingLeft="42dp"
                android:gravity="center_vertical"
                android:background="@drawable/selector_white"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onWhite"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:text="."
                android:textSize="30sp"
                android:background="@drawable/selector_white"
                android:gravity="center"
                android:layout_height="match_parent"/>
    
            <TextView
                android:onClick="onOrange"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:background="@drawable/selector_orange"
                android:text="="
                android:textSize="30sp"
                android:gravity="center"
                android:layout_height="match_parent"/>
        </LinearLayout>
    
    </LinearLayout>
    Layout
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true" android:drawable="@drawable/rectangle_select_orange"/>
        <item android:drawable="@drawable/rectangle_orange"/>
    
    
    </selector>
    @drawable/selector_orange
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true" android:drawable="@drawable/rectangle_select_white"/>
        <item android:drawable="@drawable/rectangle"/>
    
    </selector>
    @drawable/selector_white

    三、效果 

     

  • 相关阅读:
    数据结构 算法 — 合并顺序表
    Helloworld(C++语言)
    js收缩菜单
    js日期操作函数
    Oracle 查询 ORA-01722
    初识spring boot(学习中,请多多指教)
    对数据库进行黑盒测试操作?
    虚拟机每次开机都恢复初始化原因
    SecureCRT仿真Linux颜色黑白问题
    《Pro Git》一、阅读理解开篇
  • 原文地址:https://www.cnblogs.com/suanai/p/12249107.html
Copyright © 2011-2022 走看看