【开源】ActivityOptionsICS
ActivityOptionsICS
- https://github.com/tianzhijiexian/ActivityOptionsICS
介绍:
如果你在考虑如何自定义activity的切换动画,你可能会想到ActivityOptions ,但是ActivityOptions是4.1之后才有的,而ActivityOptionsICS让ActivityOptions的动画实现兼容兼容4.x或2.x运行效果:
![]()
使用说明:
makeCustomAnimation
|
1
2
3
4
5
|
public void customAnim() { ActivityOptionsCompatICS options = ActivityOptionsCompatICS.makeCustomAnimation(this, R.anim.slide_bottom_in, R.anim.slide_bottom_out); ActivityCompatICS.startActivity(MainActivity.this, intent, options.toBundle()); } |
makeScaleUpAnimation
|
1
2
3
4
5
6
|
public void scaleUpAnim(View view) { ActivityOptionsCompatICS options = ActivityOptionsCompatICS.makeScaleUpAnimation(view, 0, 0, //拉伸开始的坐标 view.getMeasuredWidth(), view.getMeasuredHeight());//初始的宽高 ActivityCompatICS.startActivity(MainActivity.this, intent, options.toBundle()); } |
makeThumbnailScaleUpAnimation
|
1
2
3
4
5
6
7
8
9
|
public void thumbNailScaleAnim(ImageView view) { view.setDrawingCacheEnabled(true); Bitmap bitmap = view.getDrawingCache(); ActivityOptionsCompatICS options = ActivityOptionsCompatICS.makeThumbnailScaleUpAnimation( view, bitmap, 0, 0); // Request the activity be started, using the custom animation options. ActivityCompatICS.startActivity(MainActivity.this, intent, options.toBundle()); //view.setDrawingCacheEnabled(false); } |
makeSceneTransitionAnimation
|
1
2
3
4
5
6
7
8
9
10
11
|
screenTransitAnimByPair( Pair.create((View)orginalImageView, R.id.target_imageView), Pair.create((View)orginalTextView, R.id.target_textView), Pair.create((View)chromeIView, R.id.target_chrome_imageView)); public void screenTransitAnimByPair(Pair<View, Integer>... views) { isSceneAnim = true; ActivityOptionsCompatICS options = ActivityOptionsCompatICS.makeSceneTransitionAnimation( MainActivity.this, views); ActivityCompatICS.startActivity(MainActivity.this, intent, options.toBundle()); } |
在目标activity中
修改成translucentTheme主题
|
1
2
3
|
<style name="TranslucentTheme" parent="AppBaseTheme"> <item name="android:windowIsTranslucent">true</item></style |
设置主题
|
1
2
3
|
<activity android:name="com.example.activityoptionsjbtest.TargetActivity" android:theme="@style/TranslucentTheme" /> |
在目标activity中开始动画
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
public class TargetActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_target); TransitionCompat.startTransition(this, R.layout.activity_target); } @Override public void onBackPressed() { //super.onBackPressed(); TransitionCompat.finishAfterTransition(this); }} |
posted on 2015-04-09 09:35 wasdchenhao 阅读(109) 评论(0) 收藏 举报

浙公网安备 33010602011771号