public void setupSaveButton() { // put save button on screen mSaveButton = new Button(MainScreen.thiz); mSaveButton.setBackgroundResource(R.drawable.button_save_background); mSaveButton.setOnClickListener(this); LayoutParams saveLayoutParams = new LayoutParams( (int) (MainScreen.mainContext .getResources() .getDimension(R.dimen.postprocessing_savebutton_size)), (int) (MainScreen.mainContext .getResources() .getDimension(R.dimen.postprocessing_savebutton_size))); saveLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); saveLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); saveLayoutParams.setMargins( (int) (MainScreen.thiz.getResources().getDisplayMetrics().density * 8), (int) (MainScreen.thiz.getResources().getDisplayMetrics().density * 8), 0, 0); ((RelativeLayout) postProcessingView.findViewById(R.id.sequenceLayout)) .addView(mSaveButton, saveLayoutParams); mSaveButton.setRotation(mLayoutOrientationCurrent); }
public void onOrientationChanged(int orientation) { if (orientation != mDisplayOrientationCurrent) { mDisplayOrientationCurrent = orientation; mLayoutOrientationCurrent = (orientation == 0 || orientation == 180) ? orientation + 90 : orientation - 90; if (postProcessingRun) mSaveButton.setRotation(mLayoutOrientationCurrent); } }
/** 根据当前手机方向,旋转各个按钮的方向 */ private void setViewRotation() { int orientation = (360 - current_orientation) % 360; mBtnCancel.setRotation(orientation); mBtnHandler.setRotation(orientation); mBtnTakePic.setRotation(orientation); mBtnChangeFacing.setRotation(orientation); mBtnFlash1.setRotation(orientation); mBtnFlash2.setRotation(orientation); mBtnFlash3.setRotation(orientation); mIvPreShow.setRotation(orientation); }