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

    三、效果 

     

  • 相关阅读:
    更改Linux时区的两种方法
    Azure上部署FTP服务
    log4j2简单使用
    elasticsearch5.5.2环境搭建
    springTask和Schedule学习
    防止SpringMVC拦截器拦截js等静态资源文件
    Mysql中使用FIND_IN_SET解决IN条件为字符串时只有第一个数据可用的问题
    ServletContext总结
    window.location.href和window.location.replace的区别
    javadoc文档
  • 原文地址:https://www.cnblogs.com/suanai/p/12249107.html
Copyright © 2011-2022 走看看