Imitate the tile effect where you go

Source: Internet
Author: User

Feel where the page did very good, very good-looking, so want to imitate. In fact, the implementation is still very easy. is to press down the run to reduce the animation, lifted back to normal state, such effect is called the tile effect. As the name implies, it feels like a tile.

Let's take a look at the following:


Let's take a look at the most important code of our own definition:

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 ispressed;private Scaleanim ation zoominanimation;private scaleanimation zoomoutanimation;public Homemenubutton (Context context) {This (context, NULL);} Public Homemenubutton (context context, AttributeSet Attrs) {Super (context, attrs); init ();} @Overrideprotected void onmeasure (int widthmeasurespec, int heightmeasurespec) {super.onmeasure (Widthmeasurespec, HEIGHTMEASURESPEC);} private void Init () {/** * initialization 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 (+); 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);} @Overrideprotected void OnDraw (canvas 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 >=-SL Op && localx < getwidth () + slop&& Localy < GetHeight () + slop;} @Overridepublic boolean ontouchevent (Motionevent event) {switch (event.getaction ()) {case Motionevent.action_down: ispressed = true;//set trueinvalidate ();//Redraw this.startanimation (zoominanimation);//Run animation break;case MotionEvent.ACTION_UP:boolean Needperformclick = Ispressed;tonormalstate ();//Normal if (Needperformclick) {PerformClick ( );} break;case MotionEvent.ACTION_MOVE:final int x = (int) event.getx (), final int y = (int) event.gety (), if (!pointinview (x, y,)) {tonormalstate ();} Break;case MotionEvent.ACTION_CANCEL:case MotionEvent.ACTION_OUTSIDE:toNormalState (); break;} return true;}}
The code is almost over in the evening: just write your own code in XML and you can:

<?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 oid:orientation= "Horizontal" > <linearlayout android:layout_width= "0DP" Android:layout_ height= "Match_parent" android:layout_marginbottom= "8DP" android:layout_marginleft= "8DP" a ndroid: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:backgro und= "@drawable/icon_favoable" > </com.zqy.qunertext.HomeMenuButton> <com.zqy.qunertext.homemenubutton Androi D:id= "@+id/hb_order" android:layout_width= "match_parent" android:layout_height= "0DP" android:layout_margintop= "8DP" android:layout_weight= "2" android:background= "@drawab Le/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= "MATC H_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_pa Rent "android:layout_marginbottom=" 8DP "android:layout_marginleft=" 8DP "Android:layout_ma rginright= "8DP" android:layout_margintop= "8DP" android:layout_weight= "1" android:orientat ion= "vertical" > <com.zqy.qunertext.homemenubutton android:id= "@+id/hb_goods_manager" Android:layout_width= "Match_parent" android:layout_height= "0DP" Android:layout_we ight= "1" android:background= "@drawable/icon_goods" > </com.zqy.qunertext.homemenubutton&gt ; <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= "M Atch_parent "android:layout_height=" 0DP "android:layout_margintop=" 8DP "Andro id:layout_weight= "2" android:background= "@drawable/icon_money" > </com.zqy.qunertext.homem enubutton> <com.zqy.qunertext.homemenubutton android:id= "@+id/hb_employee_manager" Android:layout_width= "Match_parent" android:layout_height= "0DP" Android:layout_margi ntop= "8DP" android:layout_weight= "1" android:background= "@drawable/icon_manage" > </com. Zqy.qunertext.homemenubutton> </LinearLayout> </LinearLayout></LinearLayout>

OK. It's done.

The effect can also: hehe








Imitate the tile effect where you go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.