Update CameraView.java

pull/1/head
android-dataticket 8 years ago committed by GitHub
parent 6d65d6f10d
commit e04fb369a6
  1. 39
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java

@ -122,23 +122,28 @@ public class CameraView extends FrameLayout {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mAdjustViewBounds) { if (mAdjustViewBounds) {
Size previewSize = getPreviewSize(); Size previewSize = getPreviewSize();
if (getLayoutParams().width == LayoutParams.WRAP_CONTENT) { if(previewSize != null) {
int height = MeasureSpec.getSize(heightMeasureSpec); if (getLayoutParams().width == LayoutParams.WRAP_CONTENT) {
float ratio = (float) height / (float) previewSize.getWidth(); int height = MeasureSpec.getSize(heightMeasureSpec);
int width = (int) (previewSize.getHeight() * ratio); float ratio = (float) height / (float) previewSize.getWidth();
super.onMeasure( int width = (int) (previewSize.getHeight() * ratio);
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), super.onMeasure(
heightMeasureSpec MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
); heightMeasureSpec
return; );
} else if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) { return;
int width = MeasureSpec.getSize(widthMeasureSpec); } else if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
float ratio = (float) width / (float) previewSize.getHeight(); int width = MeasureSpec.getSize(widthMeasureSpec);
int height = (int) (previewSize.getWidth() * ratio); float ratio = (float) width / (float) previewSize.getHeight();
super.onMeasure( int height = (int) (previewSize.getWidth() * ratio);
widthMeasureSpec, super.onMeasure(
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) widthMeasureSpec,
); MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
);
return;
}
}else{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
return; return;
} }
} }

Loading…
Cancel
Save