多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > 模仿去哪兒的磁貼效果

模仿去哪兒的磁貼效果

來源:程序員人生   發布時間:2014-11-14 08:38:32 閱讀次數:3328次

感覺去哪兒的頁面做的非常不錯,非常好看,因而想模仿1下,其實實現還是很簡單的,就是按下去的履行縮小動畫,抬起的恢復正常狀態,這類效果叫磁貼效果,顧名思義感覺就磁貼1樣。下面我們來看看效果圖:


下面我們來看看最重要的自定義代碼:

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 ScaleAnimation zoomInAnimation; private ScaleAnimation zoomOutAnimation; public HomeMenuButton(Context context) { this(context,null); } public HomeMenuButton(Context context, AttributeSet attrs) { super(context, attrs); init(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } private void init() { /** * 初始化動畫 */ 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 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; } @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: isPressed = true;//設置true invalidate();//重繪 this.startAnimation(zoomInAnimation);//履行動畫 break; case MotionEvent.ACTION_UP: boolean needPerformClick = isPressed; toNormalState();//正常 if (needPerformClick) { performClick(); } 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; } }
上面代碼晚上幾近就已完成了:只有把自定義的代碼寫在XML里面就能夠了:

<?xml version="1.0" encoding="utf⑻"?> <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.大功告成。效果還可以:呵呵



下載地址:






生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 性欧美黑人 | 极品久久 | 日本亚洲精品成人 | 国产粉嫩00福利福利福利 | 国产精品亚洲综合一区 | 日本一区视频在线观看 | 亚洲欧洲国产成人综合一本 | 美日韩精品 | 美国一区二区三区 | 欧美一级淫片漂亮的老师 | 亚洲国产第一页 | 性欧美高清精品video | 一级毛片免费一级直接观看 | 久久精品www| 最新国产福利 | 国产亚洲精品美女久久久久 | 国产精品视频视频久久 | 精品中文字幕一区二区三区四区 | 午夜dj影视大全视频 | 亚洲韩国欧美 | 久久综合精品国产一区二区三区 | 免费视频观看在线www日本 | 亚洲欧美久久精品 | 亚洲一区二区三区91 | 欧美日韩精品一区二区 | h视频免费观看 | 国产亚洲人成网站观看 | a天堂中文在线 | 日本欧美一区二区三区片 | 吃奶添下面大尺度视频 | 欧美视频一区二区在线观看 | 久久精品国产免费 | 亚洲成人网在线 | 国产毛片在线看 | 欧美一级欧美一级在线播放 | 免费看成人国产一区二区三区 | 欧美一级在线播放 | 日本乱性 | 爱爱小视频在线看免费 | 国产成人黄网址在线视频 | 亚洲激情专区 |