国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現移動小球和CircularReveal頁面切換動畫實例代碼

2019-10-22 18:27:46
字體:
來源:轉載
供稿:網友

前言

本文主要給大家介紹了關于Android如何實現移動小球和CircularReveal頁面切換動畫的相關內容,分享出來供大家參考學習,下面話不多說了,來一起看看詳細的介紹吧。

效果圖如下

android,小球隨機移動,頁面切換動畫,circularreveal

是在fragment中跳轉activity實現的效果,fragment跳fragment,activity跳activity類似~~

實現過程

  • 重寫FloatingActionButton的onTouchListener()方法,使小球可以移動,并判斷邊界
  • 點擊fab時記錄坐標傳到下一個頁面,在下一個頁面展示動畫。
  • 點擊后退或者重寫onBackPressed()方法,執行動畫

重寫Fab的onTouchListener()

 floatingActionButton.setOnTouchListener(new View.OnTouchListener() {  @Override  public boolean onTouch(View view, MotionEvent ev) {  switch (ev.getAction()) {   case MotionEvent.ACTION_DOWN:   downX = ev.getX();   downY = ev.getY();   isClick = true;   break;   case MotionEvent.ACTION_MOVE:   isClick = false;   moveX = ev.getX();   moveY = ev.getY();   int offsetX = (int) (moveX - downX);   int offsetY = (int) (moveY - downY);   //這里使用了setTranslation來移動view。。。嘗試過layout。不知道為什么fragment切換回來的時候會恢復原位   floatingActionButton.setTranslationX(floatingActionButton.getTranslationX() + offsetX);   floatingActionButton.setTranslationY(floatingActionButton.getTranslationY() + offsetY);   break;   case MotionEvent.ACTION_UP:   //用來觸發點擊事件   if (isClick) {    startAct();    return false;   }   //用來判斷移動邊界   if (floatingActionButton.getX() < 0) {    floatingActionButton.setX(0);   }   if (floatingActionButton.getX() + floatingActionButton.getWidth() > ScreenUtil.getScreenWidth(getContext())) {    floatingActionButton.setX(ScreenUtil.getScreenWidth(getContext()) - floatingActionButton.getWidth());   }   if (floatingActionButton.getY() < titleHeight) {    floatingActionButton.setY(0);   }   if (floatingActionButton.getY() + floatingActionButton.getHeight() + titleHeight >    getActivity().findViewById(R.id.activity_main_mainLl).getHeight() - getActivity().findViewById(R.id.fc_rg).getHeight()) {    floatingActionButton.setY(getBottomY());   }   break;  }  return true;  }  private void startAct() {  //跳轉Activity,傳遞動畫參數  Intent intent = new Intent(getActivity(), CheckWorkActivity.class);  intent.putExtra("x", (int) floatingActionButton.getX() + floatingActionButton.getWidth() / 2);  intent.putExtra("y", (int) floatingActionButton.getY() + floatingActionButton.getHeight() / 2);  intent.putExtra("start_radius", floatingActionButton.getWidth() / 2);  intent.putExtra("end_radius", DialogFragment.this.view.getHeight());  startActivity(intent);  } });

在下一個頁面中實現CircleRevel動畫

onCrete中調用

 private void initAnimation() { //ll為根布局 final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll); linearLayout.post(new Runnable() {  @Override  public void run() {  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {   Animator animator = ViewAnimationUtils.createCircularReveal(    linearLayout,// 操作的視圖    getIntent().getIntExtra("x", 0), // 動畫的中心點X    getIntent().getIntExtra("y", 0) + findViewById(R.id.title).getHeight(), // 動畫的中心點Y    getIntent().getIntExtra("start_radius", 0), // 動畫半徑    getIntent().getIntExtra("end_radius", 0)  // 動畫結束半徑   );   animator.setInterpolator(new AccelerateInterpolator());   animator.setDuration(500);   animator.start();  }  } }); }

點擊后退或者觸發onBackPressed時候調用

 private void endAnim() { final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {  Animator animator = ViewAnimationUtils.createCircularReveal(   linearLayout,// 操作的視圖   getIntent().getIntExtra("x", 0),   getIntent().getIntExtra("y", 0) + findViewById(R.id.title).getHeight(),   getIntent().getIntExtra("end_radius", 0),   getIntent().getIntExtra("start_radius", 0)  );  animator.setInterpolator(new AccelerateInterpolator());  animator.setDuration(500);  animator.addListener(new AnimatorListenerAdapter() {  @Override  public void onAnimationEnd(Animator animation) {   super.onAnimationEnd(animation);   finish();  }  });  animator.start(); } }

還有一個重要的地方是修改兩個activity的theme

 <style name="AppThemeCircleRevel" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/blue</item> <item name="android/212126.html">android:windowAnimationStyle">@null</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowIsTranslucent">true</item> <item name="android:colorBackgroundCacheHint">@null</item> </style>

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對VEVB武林網的支持。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 建德市| 岳阳县| 牙克石市| 庆城县| 阜南县| 揭阳市| 霍城县| 林芝县| 台东市| 澎湖县| 塔城市| 高邑县| 泾阳县| 新化县| 光山县| 慈溪市| 习水县| 唐山市| 梁山县| 房山区| 五河县| 荣昌县| 河间市| 武夷山市| 论坛| 南宫市| 青阳县| 九龙坡区| 潼关县| 垣曲县| 普定县| 资溪县| 淄博市| 介休市| 屯昌县| 呼和浩特市| 永德县| 侯马市| 侯马市| 阜康市| 巨野县|