• 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

    三、效果 

     

  • 相关阅读:
    POJ_3176_Cow_Bowling_(数字三角形)_(动态规划)
    POJ_3662_Telephone_Lines_(二分+最短路)
    POJ_2739_Sum_of_Consecutive_Prime_Numbers_(尺取法+素数表)
    POJ_3685_Matrix_(二分,查找第k大的值)
    POJ_3579_Median_(二分,查找第k大的值)
    欧拉回路
    状态压缩dp(hdu2167,poj2411)
    poj1182食物链(种类并查集)
    并查集
    树形动态规划
  • 原文地址:https://www.cnblogs.com/suanai/p/12249107.html
Copyright © 2020-2023  润新知