向左滑动&向右滑动动画

时间:2015-10-28 03:17:25

标签: android animation transition

假设我在Activity布局中有一个TextView(作为书页),我想在更改TextView文本(作为书)之后滑动活动布局而不完成活动 我可以通过此代码进行此转换

startActivity(i2);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_right);
this.finish();

但我不想完成当前的活动。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

我发明了一种在Activity

中为所有视图设置动画的方法
private void doNextPage() {
    final ImageView imageView= new ImageView(this);
    final FrameLayout frameLayout=(FrameLayout)findViewById(android.R.id.content);
    LinearLayout linearLayout=(LinearLayout) frameLayout.findViewById(R.id.rootContainer);
    imageView.setImageBitmap(getBitmapFromView(frameLayout));
    frameLayout.addView(imageView, 1, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));

    --------------------  Do Changes -------------------

    Animation slideOutRight = AnimationUtils.loadAnimation(this,
            R.anim.slide_out_right);
    imageView.startAnimation(slideOutRight);
    slideOutRight.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            frameLayout.removeView(imageView);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
    Animation slideInRight = AnimationUtils.loadAnimation(this,
            R.anim.slide_in_right);
    linearLayout.startAnimation(slideInRight);
}

public static Bitmap getBitmapFromView(View view) {
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    Drawable bgDrawable =view.getBackground();
    if (bgDrawable!=null)
        bgDrawable.draw(canvas);
    else
        canvas.drawColor(Color.TRANSPARENT);
    view.draw(canvas);
    return returnedBitmap;
}