I feel that the page where I go is doing very well and very nice. So I want to imitate it. In fact, the implementation is very simple, that is, to press down the animation and lift it back to normal, this effect is called the tile effect. As the name suggests, it feels the same as the tile. Let's take a look:
Next let's take a look at the most important custom code:
Package COM. zqy. qunertext; import android. content. context; import android. graphics. canvas; import android. util. attributeset; import android. util. typedvalue; import android. view. motionevent; import android. view. animation. animation; import android. view. animation. scaleanimation; import android. widget. framelayout;/***** @ author zqy **/public class homemenubutton extends framelayout {private Boolean ispress Ed; private scaleanimation zoominanimation; private scaleanimation attributes; Public homemenubutton (context) {This (context, null);} public homemenubutton (context, attributeset attrs) {super (context, attrs); Init () ;}@ overrideprotected void onmeasure (INT widthmeasurespec, int heightmeasurespec) {super. onmeasure (widthmeasurespec, heightmeasurespec);} private void Init () {/*** initialize the animation * /Zoominanimation = new scaleanimation (1f, 0.95f, 1f, 0.95f, animation. relative_to_self, 0.5f, animation. relative_to_self, 0.5f); zoominanimation. setfillafter (true); zoominanimation. setduration (200); zoomoutanimation = new scaleanimation (0.95f, 1f, 0.95f, 1f, animation. relative_to_self, 0.5f, animation. relative_to_self, 0.5f); zoomoutanimation. setfillafter (true); zoomoutanimation. setduration (200);} @ override Protected void ondraw (canvas) {super. ondraw (canvas);} private void tonormalstate () {ispressed = false; invalidate (); startanimation (zoomoutanimation);} private Boolean pointinview (float localx, float localy, float slop) {return localx> =-slop & localy> =-slop & localx <getwidth () + slop & localy <getheight () + slop ;} @ overridepublic Boolean ontouchevent (motionevent event) {Switch (event. ge Taction () {Case motionevent. action_down: ispressed = true; // set trueinvalidate (); // re-paint this. startanimation (zoominanimation); // execute the animation break; Case motionevent. action_up: Boolean need1_mclick = ispressed; tonormalstate (); // normal if (need1_mclick) {1_mclick ();} break; Case motionevent. action_move: Final int x = (INT) event. getx (); Final int y = (INT) event. gety (); If (! Pointinview (X, Y, 20) {tonormalstate ();} break; Case motionevent. action_cancel: Case motionevent. action_outside: tonormalstate (); break;} return true ;}}
The above code is almost completed at night: you only need to write the custom code in XML:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" android:orientation="horizontal" > <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginBottom="8dp" android:layout_marginLeft="8dp" android:layout_marginTop="8dp" android:layout_weight="1" android:orientation="vertical" > <com.zqy.qunertext.HomeMenuButton android:id="@+id/hb_ad" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="2" android:background="@drawable/icon_favoable" > </com.zqy.qunertext.HomeMenuButton> <com.zqy.qunertext.HomeMenuButton android:id="@+id/hb_order" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="8dp" android:layout_weight="2" android:background="@drawable/icon_order" > </com.zqy.qunertext.HomeMenuButton> <com.zqy.qunertext.HomeMenuButton android:id="@+id/hb_cloud_manger" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="8dp" android:layout_weight="1" android:background="@drawable/icon_favorable_manger" > </com.zqy.qunertext.HomeMenuButton> <com.zqy.qunertext.HomeMenuButton android:id="@+id/hb_setting" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="8dp" android:layout_weight="1" android:background="@drawable/icon_setting" > </com.zqy.qunertext.HomeMenuButton> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginBottom="8dp" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:layout_marginTop="8dp" android:layout_weight="1" android:orientation="vertical" > <com.zqy.qunertext.HomeMenuButton android:id="@+id/hb_goods_manager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@drawable/icon_goods" > </com.zqy.qunertext.HomeMenuButton> <com.zqy.qunertext.HomeMenuButton android:id="@+id/hb_store_net" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="8dp" android:layout_weight="2" android:background="@drawable/icon_store" > </com.zqy.qunertext.HomeMenuButton> <com.zqy.qunertext.HomeMenuButton android:id="@+id/hb_incoming" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="8dp" android:layout_weight="2" android:background="@drawable/icon_money" > </com.zqy.qunertext.HomeMenuButton> <com.zqy.qunertext.HomeMenuButton android:id="@+id/hb_employee_manager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="8dp" android:layout_weight="1" android:background="@drawable/icon_manage" > </com.zqy.qunertext.HomeMenuButton> </LinearLayout> </LinearLayout></LinearLayout>
OK. All done. The effect can also be: Haha
:
Imitating the effect of the tile