欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android屬性動(dòng)畫特點(diǎn)詳解

 更新時(shí)間:2018年11月26日 10:00:32   作者:FanRQ_  
這篇文章主要為大家詳細(xì)介紹了Android屬性動(dòng)畫特點(diǎn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android屬性動(dòng)畫使用的具體代碼,供大家參考,具體內(nèi)容如下

MainActivity.java

/*
屬性動(dòng)畫的特點(diǎn):動(dòng)畫效果會(huì)改變控件的位置.且開啟動(dòng)畫的是動(dòng)畫對(duì)象,而不是控件對(duì)象.
    只有旋轉(zhuǎn)的屬性動(dòng)畫是經(jīng)常用的,注意參數(shù).
    注意:這些方法都是安卓在3.0以后出現(xiàn)的新特性,所以要把AndroidManifest.xml里的android:minSdkVersion值修改為11以上
*/
//注釋后面有222的暫時(shí)不用管.
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

  private ImageButton imageView;
  private Button alpha_bt;
  private Button rotationY_bt;
  private Button scaleX_bt;
  private Button translationX_bt;
  private Button AnimatorSet_bt;


  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
//    對(duì)控件進(jìn)行初始化
    init();

//   此處用的是xml的形式.引用在Xml里的屬性動(dòng)畫資源. AnimatorInflater.loadAnimator(上下文,R.animator..)222
    Animator Xmlanimator = AnimatorInflater.loadAnimator(this, R.animator.objectanimator);
//   把要做動(dòng)畫控件對(duì)象放進(jìn)去.Animator.setTarget(View對(duì)象);222
    Xmlanimator.setTarget(imageView);
//   開啟動(dòng)畫.Animator.start.222
    Xmlanimator.start();

  }

  // 對(duì)于控件進(jìn)行初始化
  private void init() {
    //找到ImageView控件對(duì)象
    imageView = (ImageButton) findViewById(R.id.animation_iv);
    //找到Button控件對(duì)象.
    alpha_bt = (Button) findViewById(R.id.alpha_bt);
    rotationY_bt = (Button) findViewById(R.id.rotationY_bt);
    scaleX_bt = (Button) findViewById(R.id.scaleX_bt);
    translationX_bt = (Button) findViewById(R.id.translationY_bt);
    AnimatorSet_bt = (Button) findViewById(R.id.AnimatorSet_bt);
    //為button設(shè)置點(diǎn)擊事件
    alpha_bt.setOnClickListener(this);
    rotationY_bt.setOnClickListener(this);
    scaleX_bt.setOnClickListener(this);
    translationX_bt.setOnClickListener(this);
    AnimatorSet_bt.setOnClickListener(this);

  }

  /**
   * 根據(jù)點(diǎn)擊事件類型.調(diào)用控件做屬性動(dòng)畫的
   *
   * @param view
   */
  @Override
  public void onClick(View view) {
    switch (view.getId()) {
      case R.id.alpha_bt:
        //做透明動(dòng)畫,參數(shù)1:View,代表你要修改那個(gè)控件的屬性. 參數(shù)2:propertyName代表實(shí)現(xiàn)什么樣子的動(dòng)畫:"alpha",String類型.
        //參數(shù)3:float... values,控件修改的參數(shù),new float[]{0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f}
        ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", new float[]{0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f});
        //設(shè)置動(dòng)畫執(zhí)行時(shí)長.setDuration
        alpha.setDuration(2000);
        //設(shè)置動(dòng)畫執(zhí)行的模式setRepeatMode,參數(shù)用ObjectAnimator引用.
        alpha.setRepeatMode(ObjectAnimator.RESTART);
        //設(shè)置動(dòng)畫執(zhí)行的次數(shù).setRepeatCount
        alpha.setRepeatCount(1);
        //使用ObjectAnimator對(duì)象開啟動(dòng)畫.
        alpha.start();

        break;
      case R.id.rotationY_bt:
        //做旋轉(zhuǎn)動(dòng)畫,"rotationY".rotationX,rotation new float[]{90f, 180f, 270f, 360f}
        ObjectAnimator rotationY = ObjectAnimator.ofFloat(imageView, "rotationY", new float[]{90f, 180f, 270f, 360f});
        rotationY.setDuration(2000);
        rotationY.setRepeatMode(ObjectAnimator.RESTART);
        rotationY.setRepeatCount(1);
        rotationY.start();
        break;
      case R.id.scaleX_bt:
        //做縮放動(dòng)畫,scaleX,scaleY new float[]{1f, 2f, 3f, 4f, 5f, 6f,1f}
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", new float[]{1f, 2f, 3f, 4f, 5f, 6f, 1f});
        scaleX.setDuration(2000);
        scaleX.setRepeatMode(ObjectAnimator.RESTART);
        scaleX.setRepeatCount(1);
        scaleX.start();

        break;
      case R.id.translationY_bt:
        //做平移動(dòng)畫,translationY,translationX new float[]{10f, 20f, 30f, 40f, 60f, 80f}
        ObjectAnimator translationY = ObjectAnimator.ofFloat(imageView, "translationY", new float[]{10f, 20f, 30f, 40f, 60f, 80f});
        translationY.setDuration(2000);
        translationY.setRepeatMode(ObjectAnimator.RESTART);
        translationY.setRepeatCount(1);
        translationY.start();

        //做動(dòng)畫集合AnimatorSet,分別創(chuàng)建兩個(gè)動(dòng)畫對(duì)象.注意playTogether(動(dòng)畫對(duì)象...)和playSequentially的區(qū)別.最后開啟動(dòng)畫.start
      case R.id.AnimatorSet_bt:
        AnimatorSet set = new AnimatorSet();
        ObjectAnimator oa = ObjectAnimator.ofFloat(imageView, "translationX", new float[]{10f, 20f, 30f, 40f, 60f, 80f});
        oa.setDuration(3000);
        ObjectAnimator oa2 = ObjectAnimator.ofFloat(imageView, "translationY", new float[]{-10f, -20f, -30f, -40f, -60f, -80f});
        oa2.setDuration(3000);
        set.playTogether(oa, oa2);
        set.start();
        break;
      default:
        break;
    }
  }

}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
<!--  注意background的屬性置為null -->

  <Button
    android:id="@+id/alpha_bt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="alpha"/>

  <Button
    android:id="@+id/translationY_bt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="translationY"/>

  <Button
    android:id="@+id/scaleX_bt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="scaleX"/>

  <Button
    android:id="@+id/rotationY_bt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="rotationY"/>

  <Button
    android:id="@+id/AnimatorSet_bt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="AnimatorSet"/>

  <ImageButton
    android:onClick="yyyy"
    android:id="@+id/animation_iv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@drawable/a8"
    android:background="@null"/>

</LinearLayout>


在res目錄下創(chuàng)建animator文件夾在文件夾里創(chuàng)建以下xml

objectanimator.xml

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
  android:propertyName="rotationX"
  android:duration="3000"
  android:repeatCount="1"
  android:repeatMode="reverse"
  android:startOffset="0"
  android:valueFrom="360.0">
</objectAnimator>

<!--注意:在xml定義動(dòng)畫類的屬性,浮點(diǎn)型小數(shù),直接寫小數(shù)即可,不用再帶f.
提示:控件位移的參照單位在xml文件里有所不同,不過更簡單,不用再特意去定義參照物屬性了,直接是根據(jù)值,區(qū)分兩種方式:
  一種是以整個(gè)屏幕為參照物,在xml文件屬性定義值是int%p;  一種以控件自身大小為參照物,在xml文件屬性定義值是int-->

---------------------
作者:FanRQ_
來源:CSDN
原文:https://blog.csdn.net/FanRQ_/article/details/84072052
版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請附上博文鏈接!

相關(guān)文章

  • 詳解Android數(shù)據(jù)存儲(chǔ)之SQLCipher數(shù)據(jù)庫加密

    詳解Android數(shù)據(jù)存儲(chǔ)之SQLCipher數(shù)據(jù)庫加密

    對(duì)于已經(jīng)ROOT的手機(jī)來說的沒有任何安全性可以,一旦被利用將會(huì)導(dǎo)致數(shù)據(jù)庫數(shù)據(jù)的泄漏,本篇文章主要介紹了Android數(shù)據(jù)存儲(chǔ)之SQLCipher數(shù)據(jù)庫加密,具有一定的參考價(jià)值,有需要的可以了解一下。
    2016-12-12
  • Android Gradle Plug 4.1.0 升級(jí)后gradle獲取manifest位置失敗問題解決

    Android Gradle Plug 4.1.0 升級(jí)后gradle獲取manifest位置失敗問題解決

    這篇文章主要介紹了Android Gradle Plug 4.1.0 升級(jí)后gradle獲取manifest位置失敗問題解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • Android仿今日頭條頂部導(dǎo)航欄效果的實(shí)例代碼

    Android仿今日頭條頂部導(dǎo)航欄效果的實(shí)例代碼

    這篇文章主要介紹了Android之仿今日頭條頂部導(dǎo)航欄效果的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,一起跟隨小編過來看看吧
    2018-05-05
  • Android XML數(shù)據(jù)的三種解析方式

    Android XML數(shù)據(jù)的三種解析方式

    這篇文章主要為大家詳細(xì)介紹了Android XML數(shù)據(jù)的三種解析方式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android中制作自定義dialog對(duì)話框的實(shí)例分享

    Android中制作自定義dialog對(duì)話框的實(shí)例分享

    這篇文章主要介紹了Android中制作自定義dialog對(duì)話框的實(shí)例分享,安卓自帶的Dialog顯然不夠用,因而我們要繼承Dialog類來制作自己的對(duì)話框,需要的朋友可以參考下
    2016-04-04
  • Android okhttp使用的方法

    Android okhttp使用的方法

    本篇文章主要介紹了Android okhttp使用的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-02-02
  • android實(shí)現(xiàn)簡單圓弧效果

    android實(shí)現(xiàn)簡單圓弧效果

    這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)簡單圓弧效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • 三款A(yù)ndroid炫酷Loading動(dòng)畫組件推薦

    三款A(yù)ndroid炫酷Loading動(dòng)畫組件推薦

    這篇文章主要介紹了三款A(yù)ndroid炫酷Loading動(dòng)畫組件推薦,本文介紹了CircleProgress、android-shapeLoadingView、WaitingDots等三款Loading組件,并給出了運(yùn)行效果圖,需要的朋友可以參考下
    2015-05-05
  • Android編程實(shí)現(xiàn)自定義title功能示例

    Android編程實(shí)現(xiàn)自定義title功能示例

    這篇文章主要介紹了Android編程實(shí)現(xiàn)自定義title功能,結(jié)合具體實(shí)例形式分析了Android自定義title的具體實(shí)現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2017-03-03
  • android基于SwipeRefreshLayout實(shí)現(xiàn)類QQ的側(cè)滑刪除

    android基于SwipeRefreshLayout實(shí)現(xiàn)類QQ的側(cè)滑刪除

    本篇文章主要介紹了android基于SwipeRefreshLayout實(shí)現(xiàn)類QQ的側(cè)滑刪除,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2017-10-10

最新評(píng)論