模仿去哪兒的磁貼效果,模仿磁貼效果

來源:互聯網
上載者:User

模仿去哪兒的磁貼效果,模仿磁貼效果

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


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

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();}@Overrideprotected 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);}@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 >= -slop && localX < getWidth() + slop&& localY < getHeight() + slop;}@Overridepublic boolean onTouchEvent(MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:isPressed = true;//設定trueinvalidate();//重繪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-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.大功告成。效果還可以:呵呵









這期爸爸去哪兒,田亮模仿別人的老爸模仿得真像

@不減肥很多年 20樓 分房子那裡 大家都幸災樂禍的說四塊五父女分到草莓房 只有他說 我們這是落井下石吧 不合適不合適 那個樣子挺真誠 當時就被 感動 了 然後森碟臨走的時候 送老奶奶娃娃了 老奶奶抱著娃娃依依惜別 我看的眼淚都出來了 ----------------------------- 森碟送娃娃?我完全沒看到這塊……!!!!QAQ是哪一段的?
 
windows7什案頭美化軟體可以模仿win8的磁貼式介面?

首先給你一個不負責任的連結:www.oyksoft.com/soft/18912.html
這是直接搜出來的,難保能用。
另外給你個好點兒的建議,下載一個魔方最佳化大師,去IT之家,這個論壇有很多win7美化主題,用魔方破解win7主題以後就可以安裝了,不清楚有沒有磁貼的主題,但是有很多漂亮大方的主題的,說實話如果你不是win8,只裝個磁貼,會顯得很難看,win8漂亮就漂亮在metro化的磁貼和動畫搭配。相對應的,win7的aero化也可以很美觀,瀏覽器問題發不了圖,不然給你看看我的電腦主題,沒什麼大改動,但是還是看著很舒心的。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.