2015-10-28 195 views
0

假設我在Activity佈局中有一個TextView(作爲書頁工作),我想在沒有完成活動的情況下更改TextView文本(作爲書籍)之後滑動活動佈局I I可以通過此代碼進行此轉換向左滑動並向右滑動對活動的動畫

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

但我不想完成當前活動。我怎樣才能做到這一點?

回答

1

我發明了一種動畫的所有視圖在活動

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; 
}