編輯:Android 開發實例
<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/widget32" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="https://schemas.android.com/apk/res/android" > <TextView android: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> <Button android: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> <Button android: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> <Button android: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> <Button android: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>
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 {
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;
@Override
public 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) {
switch (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;
}
}
}
效果圖:

核心觀念是透過 AnimationUtils.loadAnimation() 載入各自定義的動畫 XML,再用 startAnimation() 觸發即可,四種動畫各對應一個 my_*_action 的動畫資源檔。
Android Studio 整合 OpenCV 開發環境的完整建置流程
前言 想在 Android 專案裡使用 OpenCV 進行影像處理或人臉偵測,第一步永遠是「把開發環境搭起來」。本文以 Android Studio 為主,示範如何從官方
Android 登入功能實作:從輸入欄位到錯誤次數限制
登入畫面是許多應用的第一道門。使用者要登入社群平台、雲端硬碟、內部系統,都得先通過這關。本章拆解它的三個組成部分:輸入介面、帳密比對,以及防止暴力嘗試的次數鎖。 介面:
Android 應用本地化多語系實作教學
一款 Android App 很可能會在不同國家、不同地區的裝置上被使用。為了讓應用更貼近使用者,App 應該依據裝置所在的語言環境,自動調整文字、數字、檔案等內容的呈現
Android 視圖控件架構解析:View 與 ViewGroup
控件樹的組成 Android 的視圖控件大致分為兩類:ViewGroup 與 View。ViewGroup 充當父容器,負責包含並管理子 View,兩者交錯組合便形成一棵