[android] 介面切換的簡單動畫,android切換

來源:互聯網
上載者:User

[android] 介面切換的簡單動畫,android切換

1. 建立個位移動畫的xml檔案

Activity中開啟動畫

使用AnimationUtils類載入動畫資源檔案

left_to_right.xml

<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:fromXDelta="100%"    android:toXDelta="0"    android:duration="3000"    ></translate>
View child=new IndexView(this).getMemberView();child.startAnimation(AnimationUtils.loadAnimation(this, R.anim.left_to_right));

 

 

2. 淡入淡齣動畫

當前淡出介面和執行時間

淡出過程中,淡入介面處於等待狀態

第二個介面淡入和他的執行時間

第一個介面執行完成後,要刪除掉

package com.tsh.lottery.utils;import android.support.v4.view.ViewPager;import android.view.View;import android.view.ViewGroup;import android.view.ViewParent;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;public class FadeUtil {    /**     * 淡出介面     * @param view 介面     * @param duration 執行時間     */    public static void fadeOut(final View view,long duration){        AlphaAnimation alphaAnimation=new AlphaAnimation(1, 0);        alphaAnimation.setDuration(duration);        view.startAnimation(alphaAnimation);        //監聽動畫結束,刪除View元素        alphaAnimation.setAnimationListener(new AnimationListener() {                        @Override            public void onAnimationStart(Animation animation) {            }                        @Override            public void onAnimationRepeat(Animation animation) {            }                        @Override            public void onAnimationEnd(Animation animation) {                ViewGroup vg=(ViewGroup) view.getParent();                vg.removeView(view);            }        });    }    /**     * 淡入介面     * @param view 介面     * @param delay 延遲時間     * @param duration 執行時間     */    public static void fadeIn(View view,long delay,long duration){        AlphaAnimation alphaAnimation=new AlphaAnimation(0, 1);        //設定開始時間延遲        alphaAnimation.setStartOffset(delay);        alphaAnimation.setDuration(duration);        view.startAnimation(alphaAnimation);    }}
FadeUtil.fadeOut(child, 2000);
FadeUtil.fadeIn(child, 2000,2000);

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.