android如何做iphone那種圖片抖動動畫的效果(包括button和EditText)

來源:互聯網
上載者:User

標籤:android抖動動畫

給按鈕做抖動效果,可以這樣做,建立anim檔案夾在res下面,建立一個button_shake.xml

<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="120"    android:fromDegrees="-3"    android:pivotX="100%"    android:pivotY="100%"    android:repeatCount="infinite"    android:repeatMode="reverse"    android:toDegrees="3" />

在代碼裡載入:

final ImageButton button = (ImageButton) findViewById(R.id.btn);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Animation shake = AnimationUtils.loadAnimation(AnimationTest.this, R.anim.button_shake);shake.reset();shake.setFillAfter(true);button.startAnimation(shake);}});

給EditText做一個橫向抖動的效果:

這樣寫anim的檔案:

<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="0" android:toXDelta="10" android:duration="1300" android:interpolator="@anim/cycle" />

cycle.xml主要描述動畫的加速器:

<?xml version="1.0" encoding="utf-8"?><!-- 動畫從開始到結束,變動率是迴圈給定次數的正弦曲線。 --><cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="20" />

代碼可以這樣載入:

final Button confirm = (Button) findViewById(R.id.btn_confirm);confirm.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if(custom_edittext.getText().toString().equals("jake")){Toast.makeText(AnimationTest.this, "welcome", Toast.LENGTH_LONG).show();}else{Animation shake = AnimationUtils.loadAnimation(AnimationTest.this, R.anim.shake_x);custom_edittext.startAnimation(shake);}}});

代碼可以在http://download.csdn.net/detail/baidu_nod/7616277下載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.