public void scaleView() { // instantiate the views View top_view = findViewById(R.id.topView); View bottom_view = findViewById(R.id.bottomView); LinearLayout footer = (LinearLayout) findViewById(R.id.llFooter); LinearLayout crop_frame = (LinearLayout) findViewById(R.id.llCropFrame); Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); // 90% of width crop_container_size = (int) ((float) width * (1f - (10f / 100f))); // 10% margins float margin = ((float) width * (1f - (90f / 100f))); // Parameters for white crop border LinearLayout.LayoutParams par = new LinearLayout.LayoutParams(crop_container_size, crop_container_size); par.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL; par.setMargins((int) (margin / 2f), 0, (int) (margin / 2f), 0); crop_frame.setLayoutParams(par); // Margins for other transparent views float top_view_height = ((float) (height - crop_container_size - footer.getHeight())) / (float) 2; top_view.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) top_view_height)); bottom_view.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) top_view_height)); // Image container RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(crop_container_size, crop_container_size); params.setMargins((int) (margin / 2f), (int) top_view_height, (int) (margin / 2f), 0); mImageView.setLayoutParams(params); mImageView.setImageBitmap(mBitmap); mImageView.setMaxZoom(4f); }