start activity with left to right mode

后端 未结 5 1022
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 03:27

I am facing a problem .

I have three activities and i need to start new activity with slide left.

Activity1

Activity2

Activity3

means

相关标签:
5条回答
  • 2021-02-01 04:13

    A Better approach is to create a style as follows:

    <style name="mytheme" parent="@android:style/Theme.Black">
        <item name="android:windowAnimationStyle">@style/theme</item>
    </style>
    
    <style name="theme">
        <item name="android:windowEnterAnimation">@anim/fade_in</item>
        <item name="android:windowExitAnimation">@anim/fade_out</item>
    </style>
    

    Then apply this style to your activity in manifest file using the android:theme tag.

    0 讨论(0)
  • 2021-02-01 04:17

    call overridePendingTransition before starting the SecondActivity. It takes as parameters two int enterAnim, exitAnim.

    • enterAnim is a resource ID of the animation resource to use for the incoming activity. Use 0 for no animation
    • exitAnim is a resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.
    0 讨论(0)
  • 2021-02-01 04:18

    I'll try to help you with the following example:

    res/anim/trans_left_in.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
            android:fromXDelta="100%p" 
            android:toXDelta="0" 
            android:duration="@android:integer/config_longAnimTime"/>
    </set>
    

    res/anim/trans_left_out.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate
             android:fromXDelta="0" 
             android:toXDelta="-100%p" 
             android:duration="@android:integer/config_longAnimTime"/>
    </set>
    

    res/anim/trans_right_in.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
    
        <translate 
            android:fromXDelta="-100%p" 
            android:toXDelta="0" 
            android:duration="@android:integer/config_longAnimTime"/>
    </set>
    

    res/anim/trans_right_out.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate
             android:fromXDelta="0" 
             android:toXDelta="100%p" 
             android:duration="@android:integer/config_longAnimTime"/>
    </set>
    

    src/Activity2

    @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_traces);
            overridePendingTransition(R.anim.trans_left_in, R.anim.trans_left_out);
    ...}
    
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(R.anim.trans_right_in, R.anim.trans_right_out);
    }
    
    0 讨论(0)
  • 2021-02-01 04:21

    Here it is,

    Intent intent=new Intent(Activity1.this,Activity2.class);
    startActivityForResult(intent,0);
    getActivity().overridePendingTransition( R.anim.righttoleft, R.anim.stable );
    

    And here is the animation righttoleft.xml,

    <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    
        <translate
              android:duration="500"
              android:fromXDelta="-100%"
              android:fromYDelta="0%"
              android:toXDelta="0%"
              android:toYDelta="0%" />
    </set>
    

    and stable.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
      <alpha android:fromAlpha="1.0" android:toAlpha="1.0" 
          android:interpolator="@android:anim/accelerate_interpolator" 
          android:duration="500"
          android:repeatCount="0"/>
    </set>
    
    0 讨论(0)
  • 2021-02-01 04:22

    Start activity and then just apply transition effect. For more info, how to proceed for this just visit here and for source code example visit this. For any query, feel free to comment.

    0 讨论(0)
提交回复
热议问题