Android activity之间的滑入切换

Android activity之间的滑入切换

主activity(SlidChangeActivity):

public classSlidChangeActiviry  extends Activity implements OnClickListener {

    @Override

    public void onCreate(BundlesavedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_slid_change_activiry);

       init();

    }

    

    private void init(){

       findViewById(R.id.button).setOnClickListener(this);

    }

 

    @Override

    public void onClick(View v){

       if(v.getId() == R.id.button)

       {

           Intent intent = new Intent();

           intent.setClass(SlidChangeActiviry.this, NextActivity.class);

           this.startActivity(intent);

           //如果这个地方不想用自己的,可以直接调安卓提供的动画,如下:

           overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);            

           //安卓自带的动画,看效果就知道了

//overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);

       }         

   }     

}

 

跳转到的Activity(NextActivity):

public class NextActivity extends Activity implements OnClickListener{

 

    Buttonbutton;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_next);

       button = (Button)findViewById(R.id.button);

       button.setOnClickListener(this);

    }

 

   

    @Override

    public void onClick(View v){

       if(v.getId() == R.id.button)

       {

           finish();

           //如果这个地方不想用自己的,可以直接调安卓提供的动画,如下:

           overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);

            

           //安卓自带的动画哦,看效果就知道了

           //overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);     

       }              

    }

}

 

一下是四个动画文件:


push_left_in.xml文件

<?xml version="1.0"encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

 

    <translate

        android:duration="700"

        android:fromXDelta="100%p"

        android:toXDelta="0" />

    <!-- <alpha

       android:duration="300"

       android:fromAlpha="0.0"

       android:toAlpha="1.0" /> -->

</set>

 

push_left_out.xml文件

<?xml version="1.0"encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

 

    <translate

        android:duration="700"

        android:fromXDelta="0"

        android:toXDelta="-0%p" />

   <!--  <alpha

       android:duration="300"

       android:fromAlpha="1.0"

       android:toAlpha="0.0" /> -->

</set>

push_right_in.xml文件

<?xml version="1.0"encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

 

    <translate

        android:duration="700"

        android:fromXDelta="-0%p"

        android:toXDelta="0%p" />

    <!-- <alpha

       android:duration="300"

       android:fromAlpha="0.0"

       android:toAlpha="1.0" /> -->

</set>

push_right_out.xml文件

<?xml version="1.0"encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate

        android:duration="700"

        android:fromXDelta="0"

        android:toXDelta="100%p" />

   <!--  <alpha

       android:duration="300"

       android:fromAlpha="1.0"

       android:toAlpha="0.0" /> -->

</set>

 

参考地址:http://xmagicj.diandian.com/post/2011-11-08/6613039

参考地址:http://mzh3344258.blog.51cto.com/1823534/807337


你可能感兴趣的:(Activity,Activity,切换,滑动)