Android 四種動畫效果的調用

來源:互聯網
上載者:User
在這裡, 我將每種動畫分別應用於四個按鈕為例:

 (1)  main.xml 代碼如下:(聲明四個按鈕控制項)

XML代碼:

<?xml version="1.0" encoding="utf-8"?><AbsoluteLayoutandroid:id="@+id/widget32"android:layout_width="fill_parent"android:layout_height="fill_parent"xmlns:android="http://schemas.android.com/apk/res/android"><TextViewandroid:id="@+id/widget29"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"android:layout_x="0px"android:layout_y="0px"></TextView><Buttonandroid:id="@+id/button_Alpha"android:layout_width="150px"android:layout_height="150px"android:text="Alpha動畫"android:textSize="50px"android:layout_x="0px" android:layout_y="30px"></Button><Buttonandroid:id="@+id/button_Scale"android:layout_width="150px"android:layout_height="150px"android:text="Scale動畫"android:textSize="50px"android:layout_x="0px" android:layout_y="180px"></Button><Buttonandroid:layout_width="150px"android:layout_height="150px"android:text="Translate動畫"android:layout_x="161px" android:layout_y="30px" android:textSize="30px" android:id="@+id/button_Translate"></Button><Buttonandroid:id="@+id/button_Rotate"android:layout_width="150px"android:layout_height="150px"android:text="Rotate動畫"android:layout_y="180px" android:layout_x="161px" android:textSize="44px"></Button></AbsoluteLayout>

java代碼:

import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.widget.Button;public class myActionAnimation extends Activity implements OnClickListener {/** Called when the activity is first created. */private Button button_alpha;private Button button_scale;private Button button_translate;private Button button_rotate;private Animation myAnimation_Alpha;private Animation myAnimation_Scale;private Animation myAnimation_Translate;private Animation myAnimation_Rotate;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);button_alpha = (Button) findViewById(R.id.button_Alpha);button_alpha.setOnClickListener(this);button_scale = (Button) findViewById(R.id.button_Scale);button_scale.setOnClickListener(this);button_translate = (Button) findViewById(R.id.button_Translate);button_translate.setOnClickListener(this);button_rotate = (Button) findViewById(R.id.button_Rotate);button_rotate.setOnClickListener(this);}public void onClick(View button) {// TODO Auto-generated method stubswitch (button.getId()) {case R.id.button_Alpha: {myAnimation_Alpha = AnimationUtils.loadAnimation(this,R.layout.my_alpha_action);button_alpha.startAnimation(myAnimation_Alpha);}break;case R.id.button_Scale: {myAnimation_Scale= AnimationUtils.loadAnimation(this,R.layout.my_scale_action);button_scale.startAnimation(myAnimation_Scale);}break;case R.id.button_Translate: {myAnimation_Translate= AnimationUtils.loadAnimation(this,R.layout.my_translate_action);button_translate.startAnimation(myAnimation_Translate);}break;case R.id.button_Rotate: {myAnimation_Rotate= AnimationUtils.loadAnimation(this,R.layout.my_rotate_action);button_rotate.startAnimation(myAnimation_Rotate);}break;default:break;}}}

相關文章

聯繫我們

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