【问题标题】:Running a custom animation between Android Activities在 Android Activity 之间运行自定义动画
【发布时间】:2012-04-12 00:30:39
【问题描述】:

所以我知道您可以使用 overidePendingTransition 方法在活动之间使用自己的动画。我在两个活动之间设置了一个过渡,它在我的模拟器上运行完美,但是当我将应用程序刷到手机上时,我看不到任何过渡。这怎么可能?

我的模拟器和我的手机一样运行 2.2

这是我的 onCreate 方法

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Button button = (Button) findViewById(R.id.close);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent myIntent = new Intent(ActivityTransitionActivity.this, ActivityTwo.class);
                ActivityTransitionActivity.this.startActivity(myIntent);
                overridePendingTransition(R.anim.fadein, R.anim.fadeout);

            }
        });
    }

【问题讨论】:

    标签: android android-activity


    【解决方案1】:

    在你的 style.xml 中定义你的动画

        <style  name="Animation.CustomAnimation">
            <item name="android:activityOpenEnterAnimation">@anim/slide_in_left</item> When opening a new activity, this is the animation that is run on the next activity
            <item name="android:activityOpenExitAnimation">@anim/slide_out_right</item>When opening a new activity, this is the animation that is run on the previous activity (which is exiting the screen)
            <item name="android:activityCloseEnterAnimation">@anim/slide_in_right</item>When closing the current activity, this is the animation that is run on the next activity (which is entering the screen). 
            <item name="android:activityCloseExitAnimation">@anim/slide_out_left</item>When closing the current activity, this is the animation that is run on the current activity (which is exiting the screen). 
            </style>
    
    <style parent="android:style/Theme.Light.NoTitleBar.Fullscreen" name="app_theme">
         <item name="android:windowBackground">@drawable/splash</item>
         <item name="android:windowAnimationStyle">@style/Animation.CustomAnimation</item>
    
        </style>
    

    <application android:icon="@drawable/icon" android:label="@string/app_name"
         android:theme="@style/app_theme">
    

    将 app_theme 应用到您在 android manifest 中的应用程序

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题(在三星 Galaxy S 上)。我在Activity animation not working in Galaxy Tab 找到了我的答案 结果动画在三星设备上默认关闭。 (这是一个设置:进入设置 -> 显示 -> 动画,然后打开所有动画,您将能够看到动画)

      【讨论】:

        【解决方案3】:

        试试这个,

         button.setOnClickListener(new OnClickListener() {
        
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent myIntent = new Intent(v.getContext(),
                        ActivityTwo.class);
                startActivityForResult(myIntent, 0);
                overridePendingTransition(R.anim.zoomextra, 0);
                 finish();
        
        
            }
        });
        

        【讨论】:

          猜你喜欢
          • 2017-02-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-06-27
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多