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

    三、效果 

     

  • 相关阅读:
    epoll使用(转)
    8、多线程小结(1)(转)
    9、多线程小结(2)(转)
    长连接和短连接(转)
    5、线程终止方式:(转)
    linux中read,write和recv,send的区别(转)
    数据访问函数库的使用方法(二)—— 获取记录集和使用事务的方法
    我想到的几句话。
    关于博克园T恤的一点想法。
    我自己写的一个分页控件(源码和演示代码)PostBack分页版 for vs2003、SQL Server
  • 原文地址:https://www.cnblogs.com/suanai/p/12249107.html
Copyright © 2011-2022 走看看