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

Android使用animator實現(xiàn)fragment的3D翻轉(zhuǎn)效果

 更新時間:2017年12月29日 09:54:35   作者:lrsmiracle  
這篇文章主要為大家詳細介紹了Android使用animator實現(xiàn)fragment的3D翻轉(zhuǎn)效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

今天老師留的作業(yè),使用倆個Fragment來實現(xiàn)3D翻轉(zhuǎn)效果,遇到了一點點的問題,于是在網(wǎng)上進行了查找,但是發(fā)現(xiàn)有些博主的代碼不正確,對其他人進行了誤導(dǎo),在網(wǎng)上使用屬性動畫實現(xiàn)3D效果非常少,所以經(jīng)過我自己的實驗摸索,我將自己的代碼和遇到的問題給他講解一下提供一點點借鑒,并且希望可以幫助到大家。
首先講解一下主要實現(xiàn)動畫的函數(shù):

getFragmentManager().beginTransaction()
    .setCustomAnimations(R.animator.fragment_second_3d_reversal_enter,R.animator.fragment_second_3d_reversal_exit)
    .replace(R.id.container, new MainFragment()).commit();

我想信這個函數(shù)大家在實現(xiàn)動畫時都會使用到,先獲得FragmentManager然后進行transaction,主要添加動畫的函數(shù)是setCustomAnimations(),在網(wǎng)上可以查到的解釋,對這個方法有些錯誤,描述的是當(dāng)前的Fragment對象的進入和退出時的動畫效果,是這個對象的一種屬性,但是這個方法真正的解釋應(yīng)該是在當(dāng)前Activity在切換Fragment時所執(zhí)行的動畫方式,也就是說當(dāng)前Fragment退出時用的是方法中的退出動畫,新的Fragment進入時執(zhí)行的是進入的動畫效果,可以理解為這一次動畫效果完全是利用這一個語句來完成,有些博客的記載對我們產(chǎn)生了一些誤導(dǎo)。

官方的注釋如下:

/**
 * Set specific animation resources to run for the fragments that are
 * entering and exiting in this transaction. These animations will not be
 * played when popping the back stack.
 */
public abstract FragmentTransaction setCustomAnimations(int enter, int exit);

整體的3D翻轉(zhuǎn)效果代碼如下:

第二個Fragment。

/**
 * Created by Liurs on 2016/6/14.
 **/
public class SecondFragment extends Fragment {

  private LinearLayout root;
  private Button mButton;

  public SecondFragment() {

  }

  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    root = (LinearLayout) inflater.inflate(R.layout.fragment_second, container, false);
    //Set listener;
    setListener();
    return root;
  }

  /**
   * set listener
   */
  private void setListener() {
    mButton = (Button) root.findViewById(R.id.button);
    mButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        getFragmentManager().beginTransaction()
            .setCustomAnimations(R.animator.fragment_second_3d_reversal_enter,R.animator.fragment_second_3d_reversal_exit)
            .replace(R.id.container, new MainFragment()).commit();
      }
    });
  }

  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

  }
}

第一個Fragment。

/**
 * Created by Liurs on 2016/6/14.
 **/
public class MainFragment extends Fragment {

  private LinearLayout root;
  private Button mButton;

  public MainFragment() {

  }

  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    root = (LinearLayout) inflater.inflate(R.layout.content_main, container, false);
    //Set listener;
    setListener();

    return root;
  }

  /**
   * set listener
   */
  private void setListener() {
    mButton = (Button) root.findViewById(R.id.button);
    mButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        getFragmentManager()
            .beginTransaction()
            .addToBackStack(null)
            .setCustomAnimations(R.animator.fragment_3d_reversal_enter,R.animator.fragment_3d_reversal_exit,R.animator.fragment_second_3d_reversal_enter,R.animator.fragment_second_3d_reversal_exit)
            .replace(R.id.container, new SecondFragment())
            .commit();
      }
    });
  }


  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

  }
}

逆時針翻轉(zhuǎn)動畫進入時配置文件。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="sequentially">
  <objectAnimator
    android:duration="0"
    android:propertyName="rotationY"
    android:valueFrom="0f"
    android:valueTo="270f" />
  <objectAnimator
    android:duration="500"
    android:propertyName="rotationY"
    android:startOffset="500"
    android:valueFrom="270f"
    android:valueTo="360f" />
</set>

退出時動畫配置文件,

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="sequentially">
  <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:propertyName="rotationY"
    android:valueFrom="0f"
    android:valueTo="90f">
    </objectAnimator>
</set>

順時針翻轉(zhuǎn)動畫進入時配置文件,

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
  android:ordering="sequentially">
  <objectAnimator
    android:duration="0"
    android:propertyName="rotationY"
    android:valueFrom="180f"
    android:valueTo="90f" />
  <objectAnimator
    android:duration="500"
    android:propertyName="rotationY"
    android:startOffset="500"
    android:valueFrom="90f"
    android:valueTo="0f" />
</set>

退出時動畫配置文件,

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="sequentially">
  <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:propertyName="rotationY"
    android:valueFrom="0f"
    android:valueTo="-90f">
  </objectAnimator>
</set>

至此,兩個Fragment的3D翻轉(zhuǎn)切換已經(jīng)完成,希望我的經(jīng)驗可以幫助到你們。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android 矢量室內(nèi)地圖開發(fā)實例

    Android 矢量室內(nèi)地圖開發(fā)實例

    這篇文章主要介紹了Android 矢量室內(nèi)地圖開發(fā)實例的相關(guān)資料,這里提供代碼實例,及實現(xiàn)效果圖,矢量室內(nèi)對圖簡單DEMO,需要的朋友可以參考下
    2016-11-11
  • Android studio 快捷鍵大全

    Android studio 快捷鍵大全

    android studio使用教程,主要為大家介紹的是android studio快捷鍵,如果我們掌握了一些常用快捷鍵,那么在使用android studio的過程中會達到事半功倍的效果哦
    2016-01-01
  • Android?TextView跑馬燈實現(xiàn)原理及方法實例

    Android?TextView跑馬燈實現(xiàn)原理及方法實例

    字的跑馬燈效果在移動端開發(fā)中是一個比較常見的需求場景,下面這篇文章主要給大家介紹了關(guān)于Android?TextView跑馬燈實現(xiàn)原理及方法的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • Android--SQLite(增,刪,改,查)操作實例代碼

    Android--SQLite(增,刪,改,查)操作實例代碼

    Android--SQLite(增,刪,改,查)操作實例代碼,需要的朋友可以參考一下
    2013-02-02
  • Android獲取觸摸手勢實現(xiàn)左右滑動

    Android獲取觸摸手勢實現(xiàn)左右滑動

    這篇文章主要為大家詳細介紹了Android獲取觸摸手勢實現(xiàn)左右滑動,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • 詳解android異步更新UI的幾種方法

    詳解android異步更新UI的幾種方法

    本篇文章主要介紹了詳解android異步更新UI的幾種方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • 在Android開發(fā)中替換資源圖片不起作用的解決方法

    在Android開發(fā)中替換資源圖片不起作用的解決方法

    這篇文章主要介紹了在Android開發(fā)中替換資源圖片不起作用的解決方法,需要的朋友可以參考下
    2014-07-07
  • Android新布局方式ConstraintLayout快速入門教程

    Android新布局方式ConstraintLayout快速入門教程

    谷歌在2016年的IO大會上推出的一種新的布局方式—-ConstraintLayout,這局是一種約束型的布局方式,下面這篇文章主要給大家介紹了Android中新布局方式ConstraintLayout的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-05-05
  • Android對話框AlertDialog與DatePickerDialog及TimePickerDialog使用詳解

    Android對話框AlertDialog與DatePickerDialog及TimePickerDialog使用詳解

    這篇文章主要介紹了Android對話框中的提醒對話框AlertDialog、日期對話框DatePickerDialog、時間對話框TimePickerDialog使用方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2022-09-09
  • Android?中?FrameLayout?布局及屬性的使用詳解

    Android?中?FrameLayout?布局及屬性的使用詳解

    這篇文章主要介紹了Android?中?FrameLayout?布局及屬性的使用,FrameLayout?在實現(xiàn)簡單布局時非常方便,特別適用于疊加式布局,如顯示疊加的圖層或浮動按鈕等,需要的朋友可以參考下
    2024-03-03

最新評論

拜城县| 石狮市| 通辽市| 留坝县| 华坪县| 元江| 新平| 七台河市| 桐柏县| 鲁甸县| 且末县| 台江县| 阜城县| 临猗县| 乌审旗| 广元市| 宜都市| 江油市| 襄汾县| 淳安县| 云龙县| 苏尼特左旗| 亳州市| 东乡| 宜兰市| 惠州市| 普兰店市| 台前县| 洱源县| 甘洛县| 沙湾县| 屏边| 北宁市| 于田县| 炎陵县| 扶沟县| 蒲江县| 汉源县| 东港市| 靖宇县| 湾仔区|