編輯:關於Android編程
廢話不哆嗦,直接上代碼,反正也差不多沒人看,就自己記錄下咯
package com.example.testroundmenu; import android.animation.ObjectAnimator; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.RotateAnimation; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.Toast; public class Main extends Activity { //下標分別是從下到上,從左到右 private RelativeLayout rl_1, rl_2, rl_3; private ImageView iv_rl1_home, iv_rl2_1, iv_rl2_2, iv_rl2_3, iv_rl3_1, iv_rl3_2, iv_rl3_3, iv_rl3_4, iv_rl3_5, iv_rl3_6, iv_rl3_7; private boolean isMidleMenuShow = true; private boolean isOutMenuShow = true; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); initView(); } private void initView() { MyListener listener = new MyListener(); // 初始化控件,簡單起見,並沒有直接在xml中聲明點擊函數 rl_1 = (RelativeLayout) findViewById(R.id.rl_1); rl_2 = (RelativeLayout) findViewById(R.id.rl_2); rl_3 = (RelativeLayout) findViewById(R.id.rl_3); iv_rl1_home = (ImageView) findViewById(R.id.iv_home); iv_rl2_1 = (ImageView) findViewById(R.id.iv_search); iv_rl2_2 = (ImageView) findViewById(R.id.iv_menu); iv_rl2_3 = (ImageView) findViewById(R.id.iv_myyouku); iv_rl3_1 = (ImageView) findViewById(R.id.iv_out_1); iv_rl3_2 = (ImageView) findViewById(R.id.iv_out_2); iv_rl3_3 = (ImageView) findViewById(R.id.iv_out_3); iv_rl3_4 = (ImageView) findViewById(R.id.iv_out_4); iv_rl3_5 = (ImageView) findViewById(R.id.iv_out_5); iv_rl3_6 = (ImageView) findViewById(R.id.iv_out_6); iv_rl3_7 = (ImageView) findViewById(R.id.iv_out_7); // 添加點擊監聽 iv_rl1_home.setOnClickListener(listener); iv_rl2_1.setOnClickListener(listener); iv_rl2_2.setOnClickListener(listener); iv_rl2_3.setOnClickListener(listener); iv_rl3_1.setOnClickListener(listener); iv_rl3_2.setOnClickListener(listener); iv_rl3_3.setOnClickListener(listener); iv_rl3_4.setOnClickListener(listener); iv_rl3_5.setOnClickListener(listener); iv_rl3_6.setOnClickListener(listener); iv_rl3_7.setOnClickListener(listener); } /** * @author kk_imgod imageview 的監聽函數 */ public class MyListener implements OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.iv_home: if (isMidleMenuShow) { isMidleMenuShow = false; animatrHiden(rl_2, 500); //如果最外層的菜單還在顯示的話,那就一起隱藏 if(isOutMenuShow) { animatrHiden(rl_3, 1000); isOutMenuShow = false; } } else { isMidleMenuShow = true; animatrShow(rl_2, 500); } showToast(HOME); break; case R.id.iv_menu: showToast(我的菜單); if(isOutMenuShow) { animatrHiden(rl_3, 1000); isOutMenuShow = false; } else { animatrShow(rl_3, 1000); isOutMenuShow = true; } break; case R.id.iv_search: showToast(我的搜索); break; case R.id.iv_myyouku: showToast(我的優酷); break; case R.id.iv_out_1: showToast(第一個); break; case R.id.iv_out_2: showToast(第二個); break; case R.id.iv_out_3: showToast(第三個); break; case R.id.iv_out_4: showToast(第四個); break; case R.id.iv_out_5: showToast(第五個); break; case R.id.iv_out_6: showToast(第六個); break; case R.id.iv_out_7: showToast(第七個); break; default: break; } } } /** * @param text * 顯示吐司的文本 */ public void showToast(String text) { Toast.makeText(Main.this, text, Toast.LENGTH_SHORT).show(); } /** * 讓視圖動畫顯示出來,180-360度 */ public void animatrShow(View view, long durction) { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view, rotation, 180f, 360f ); //設置旋轉點 view.setPivotX(view.getWidth() / 2); view.setPivotY(view.getHeight()); objectAnimator.setDuration(durction).start(); } /** * 讓視圖動畫隱藏起來 0-180度 */ public void animatrHiden(View view, long durction) { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view, rotation, 0f, 180f); //設置動畫的旋轉點 view.setPivotX(view.getWidth() / 2); view.setPivotY(view.getHeight()); objectAnimator.setDuration(durction).start(); } //下面的這種隱藏和顯示動畫的效果是傳統動畫,沒有交互效果 /** * @param view 0-180讓視圖隱藏 */ public static void startAnimout(RelativeLayout view) { // TODO Auto-generated method stub RotateAnimation rotateAnimation = new RotateAnimation(0, 180, view.getWidth() / 2, view.getHeight()); rotateAnimation.setDuration(500); rotateAnimation.setFillAfter(true); view.startAnimation(rotateAnimation); } /** * @param view 180-360讓視圖出現 */ public static void startAnimin(RelativeLayout view) { // TODO Auto-generated method stub RotateAnimation rotateAnimation = new RotateAnimation(180, 360, view.getWidth() / 2, view.getHeight()); rotateAnimation.setDuration(500); rotateAnimation.setFillAfter(true); view.startAnimation(rotateAnimation); } }關鍵性代碼:設置旋轉點
//設置旋轉點 view.setPivotX(view.getWidth() / 2); view.setPivotY(view.getHeight());
今天我們接著上次講的內容,介紹另一種改變圖片色彩的方法:像素;今天通過一個例子來熟悉像素操作:實現圖片的 底片,懷舊,雕塑,這三種比較有意思的效果。首先,上圖,勾引一下你
看過《Android開發藝術探索》View的繪制源碼之後,裡面在講解繪制最開始執行的方法是ViewRootImpl裡面的performTraversals,覺得有點費解,
本次分兩個大方向去講解Web Api,1、如何實現Web Api?2、如何Android端如何調用Web Api?對於Web Api是什麼?有什麼優缺點?為什麼用WebA
昨天給大家粗略的介紹了一下我那個簡單的項目:Android之基於XMPP協議即時通訊軟件(一) 從今天開始,就詳細展開的介紹設計思路,一是給自己做個總結,二