最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android編程實(shí)現(xiàn)仿iphone抖動(dòng)效果的方法(附源碼)

 更新時(shí)間:2015年11月20日 09:22:36   作者:lee0oo0  
這篇文章主要介紹了Android編程實(shí)現(xiàn)仿iphone抖動(dòng)效果的方法,結(jié)合實(shí)例形式分析了仿iphone抖動(dòng)效果的頁面布局及功能實(shí)現(xiàn)技巧,并附帶實(shí)例源碼供讀者下載,需要的朋友可以參考下

本文實(shí)例講述了Android編程實(shí)現(xiàn)仿iphone抖動(dòng)效果的方法。分享給大家供大家參考,具體如下:

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical" >
 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal">
  <TextView
   android:id="@+id/tv0"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv1"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv2"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv3"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
 </LinearLayout>
 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal">
  <TextView
   android:id="@+id/tv4"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv5"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv6"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv7"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
 </LinearLayout>
 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal">
  <TextView
   android:id="@+id/tv8"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv9"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv10"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv11"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
 </LinearLayout>
 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal">
  <TextView
   android:id="@+id/tv12"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv13"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv14"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv15"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
 </LinearLayout>
 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal">
  <TextView
   android:id="@+id/tv16"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv17"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv18"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
  <TextView
   android:id="@+id/tv19"
   android:layout_width="80dip"
   android:layout_height="94dip"
   android:drawableTop="@drawable/ic_launcher"
   android:text="@string/hello" />
 </LinearLayout>
</LinearLayout>

代碼:

package com.android.shake;
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.RotateAnimation;
import android.widget.TextView;
import android.view.View;
import android.view.Window;
public class ShakeTestActivity extends Activity implements View.OnClickListener {
 private TextView mtv0;
 private TextView mtv1;
 private TextView mtv2;
 private TextView mtv3;
 private TextView mtv4;
 private TextView mtv5;
 private TextView mtv6;
 private TextView mtv7;
 private TextView mtv8;
 private TextView mtv9;
 private TextView mtv10;
 private TextView mtv11;
 private TextView mtv12;
 private TextView mtv13;
 private TextView mtv14;
 private TextView mtv15;
 private TextView mtv16;
 private TextView mtv17;
 private TextView mtv18;
 private TextView mtv19;
 private boolean mNeedShake = false;
 private boolean mStartShake = false;
 private static final int ICON_WIDTH = 80;
 private static final int ICON_HEIGHT = 94;
 private static final float DEGREE_0 = 1.8f;
 private static final float DEGREE_1 = -2.0f;
 private static final float DEGREE_2 = 2.0f;
 private static final float DEGREE_3 = -1.5f;
 private static final float DEGREE_4 = 1.5f;
 private static final int ANIMATION_DURATION = 80;
 private int mCount = 0;
 float mDensity;
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.main);
  DisplayMetrics dm = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(dm);
  if (dm != null) {
   mDensity = dm.density;
  }
  mtv0 = (TextView) findViewById(R.id.tv0);
  mtv0.setOnClickListener(this);
  mtv1 = (TextView) findViewById(R.id.tv1);
  mtv1.setOnClickListener(this);
  mtv2 = (TextView) findViewById(R.id.tv2);
  mtv2.setOnClickListener(this);
  mtv3 = (TextView) findViewById(R.id.tv3);
  mtv3.setOnClickListener(this);
  mtv4 = (TextView) findViewById(R.id.tv4);
  mtv4.setOnClickListener(this);
  mtv5 = (TextView) findViewById(R.id.tv5);
  mtv5.setOnClickListener(this);
  mtv6 = (TextView) findViewById(R.id.tv6);
  mtv6.setOnClickListener(this);
  mtv7 = (TextView) findViewById(R.id.tv7);
  mtv7.setOnClickListener(this);
  mtv8 = (TextView) findViewById(R.id.tv8);
  mtv8.setOnClickListener(this);
  mtv9 = (TextView) findViewById(R.id.tv9);
  mtv9.setOnClickListener(this);
  mtv10 = (TextView) findViewById(R.id.tv10);
  mtv10.setOnClickListener(this);
  mtv11 = (TextView) findViewById(R.id.tv11);
  mtv11.setOnClickListener(this);
  mtv12 = (TextView) findViewById(R.id.tv12);
  mtv12.setOnClickListener(this);
  mtv13 = (TextView) findViewById(R.id.tv13);
  mtv13.setOnClickListener(this);
  mtv14 = (TextView) findViewById(R.id.tv14);
  mtv14.setOnClickListener(this);
  mtv15 = (TextView) findViewById(R.id.tv15);
  mtv15.setOnClickListener(this);
  mtv16 = (TextView) findViewById(R.id.tv16);
  mtv16.setOnClickListener(this);
  mtv17 = (TextView) findViewById(R.id.tv17);
  mtv17.setOnClickListener(this);
  mtv18 = (TextView) findViewById(R.id.tv18);
  mtv18.setOnClickListener(this);
  mtv19 = (TextView) findViewById(R.id.tv19);
  mtv19.setOnClickListener(this);
 }
 @Override
 public void onClick(View v) {
  if (!mStartShake) {
   mStartShake = true;
   mNeedShake = true;
   shakeAnimation(mtv0);
   shakeAnimation(mtv1);
   shakeAnimation(mtv2);
   shakeAnimation(mtv3);
   shakeAnimation(mtv4);
   shakeAnimation(mtv5);
   shakeAnimation(mtv6);
   shakeAnimation(mtv7);
   shakeAnimation(mtv8);
   shakeAnimation(mtv9);
   shakeAnimation(mtv10);
   shakeAnimation(mtv11);
   shakeAnimation(mtv12);
   shakeAnimation(mtv13);
   shakeAnimation(mtv14);
   shakeAnimation(mtv15);
   shakeAnimation(mtv16);
   shakeAnimation(mtv17);
   shakeAnimation(mtv18);
   shakeAnimation(mtv19);
  }
 }
 private void shakeAnimation(final View v) {
  float rotate = 0;
  int c = mCount++ % 5;
  if (c == 0) {
   rotate = DEGREE_0;
  } else if (c == 1) {
   rotate = DEGREE_1;
  } else if (c == 2) {
   rotate = DEGREE_2;
  } else if (c == 3) {
   rotate = DEGREE_3;
  } else {
   rotate = DEGREE_4;
  }
  final RotateAnimation mra = new RotateAnimation(rotate, -rotate, ICON_WIDTH * mDensity / 2, ICON_HEIGHT * mDensity / 2);
  final RotateAnimation mrb = new RotateAnimation(-rotate, rotate, ICON_WIDTH * mDensity / 2, ICON_HEIGHT * mDensity / 2);
  mra.setDuration(ANIMATION_DURATION);
  mrb.setDuration(ANIMATION_DURATION);
  mra.setAnimationListener(new AnimationListener() {
   @Override
   public void onAnimationEnd(Animation animation) {
    if (mNeedShake) {
     mra.reset();
     v.startAnimation(mrb);
    }
   }
   @Override
   public void onAnimationRepeat(Animation animation) {
   }
   @Override
   public void onAnimationStart(Animation animation) {
   }
  });
  mrb.setAnimationListener(new AnimationListener() {
   @Override
   public void onAnimationEnd(Animation animation) {
    if (mNeedShake) {
     mrb.reset();
     v.startAnimation(mra);
    }
   }
   @Override
   public void onAnimationRepeat(Animation animation) {
   }
   @Override
   public void onAnimationStart(Animation animation) {
   }
  });
  v.startAnimation(mra);
 }
 @Override
 public void onBackPressed() {
  if (!mNeedShake) {
   super.onBackPressed();
  } else {
   mNeedShake = false;
   mCount = 0;
   mStartShake = false;
  }
 }
}

完整實(shí)例代碼代碼點(diǎn)擊此處本站下載。

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android 全屏無標(biāo)題欄的三種實(shí)現(xiàn)方法

    Android 全屏無標(biāo)題欄的三種實(shí)現(xiàn)方法

    這篇文章主要介紹了Android的三種實(shí)現(xiàn)方法的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-07-07
  • Android二級(jí)緩存加載圖片實(shí)現(xiàn)照片墻功能

    Android二級(jí)緩存加載圖片實(shí)現(xiàn)照片墻功能

    這篇文章主要為大家詳細(xì)介紹了Android二級(jí)緩存加載圖片實(shí)現(xiàn)照片墻功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Android 8.0系統(tǒng)中通知欄的適配詳解

    Android 8.0系統(tǒng)中通知欄的適配詳解

    本片文章給大家通過實(shí)例講解分析了Android 8.0系統(tǒng)中通知欄的相關(guān)知識(shí)點(diǎn),對(duì)此有需要的朋友可以參考學(xué)習(xí)下。
    2018-04-04
  • Android開發(fā)新手必須知道的10大嚴(yán)重錯(cuò)誤

    Android開發(fā)新手必須知道的10大嚴(yán)重錯(cuò)誤

    這篇文章主要介紹了Android開發(fā)新手必須知道的10大嚴(yán)重錯(cuò)誤,總結(jié)分析了Android開發(fā)中幫助文件、開發(fā)工具、社區(qū)等的重要性以及重要的開發(fā)原則,需要的朋友可以參考下
    2016-01-01
  • Android 自定View實(shí)現(xiàn)仿QQ運(yùn)動(dòng)步數(shù)圓弧及動(dòng)畫效果

    Android 自定View實(shí)現(xiàn)仿QQ運(yùn)動(dòng)步數(shù)圓弧及動(dòng)畫效果

    這篇文章主要介紹了Android自定義view實(shí)現(xiàn)高仿QQ運(yùn)動(dòng)步數(shù)圓弧及動(dòng)畫效果的實(shí)例代碼,本文涉及到繪制圓弧需要具備的知識(shí)點(diǎn),需要的朋友可以參考下
    2016-10-10
  • Flutter 局部路由實(shí)現(xiàn)詳解

    Flutter 局部路由實(shí)現(xiàn)詳解

    這篇文章主要介紹了Flutter 局部路由實(shí)現(xiàn)詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • Android自定義圓環(huán)式進(jìn)度條

    Android自定義圓環(huán)式進(jìn)度條

    這篇文章主要為大家詳細(xì)介紹了Android自定義圓環(huán)式進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • Android實(shí)現(xiàn)上傳圖片功能

    Android實(shí)現(xiàn)上傳圖片功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)上傳圖片功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Android切換卡TabWidget用法示例

    Android切換卡TabWidget用法示例

    這篇文章主要介紹了Android切換卡TabWidget用法,結(jié)合實(shí)例形式分析了TabWidget選項(xiàng)卡界面布局及功能實(shí)現(xiàn)的操作技巧,需要的朋友可以參考下
    2016-08-08
  • Android選項(xiàng)菜單用法實(shí)例分析

    Android選項(xiàng)菜單用法實(shí)例分析

    這篇文章主要介紹了Android選項(xiàng)菜單用法,以完整實(shí)例形式較為詳細(xì)分析了Android選項(xiàng)菜單的布局及功能實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09

最新評(píng)論

元阳县| 封丘县| 临朐县| 岳池县| 正定县| 田阳县| 东莞市| 皮山县| 炎陵县| 佛教| 崇左市| 华容县| 关岭| 龙川县| 古蔺县| 东阳市| 丘北县| 东丽区| 甘肃省| 汽车| 文昌市| 监利县| 广德县| 永康市| 保德县| 德钦县| 浠水县| 兴隆县| 广汉市| 新巴尔虎左旗| 刚察县| 清河县| 鄂州市| 奉新县| 延津县| 越西县| 余庆县| 永安市| 桃园县| 资源县| 清徐县|