下面列出了android.view.SurfaceView#getLayoutParams ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void updateMotionPreferences() {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
if (mCam != null) {
mCam.updateFromPreferences(prefs);
}
if (mMotionDetector != null) {
mMotionDetector.updateFromPreferences(prefs);
}
SurfaceView motionView = findViewById(R.id.motionView);
boolean showPreview = prefs.getBoolean(Constants.PREF_MOTION_DETECTION_PREVIEW, false);
if (showPreview && mCam != null && mCam.canBeUsed()) {
ViewGroup.LayoutParams params = motionView.getLayoutParams();
params.height = 480;
params.width = 640;
motionView.setLayoutParams(params);
motionView.setVisibility(View.VISIBLE);
} else {
motionView.setVisibility(View.INVISIBLE);
}
}
private void changePlayerSize(int pictureWidth, int pictureHeight) {
View root = findViewById(R.id.root);
SurfaceView surfaceView = findViewById(R.id.surface_view);
Size changeSize;
Size viewSize = new Size(root.getWidth(), root.getHeight());
changeSize = calculateViewSize(pictureWidth, pictureHeight, viewSize);
ViewGroup.LayoutParams layoutParams = surfaceView.getLayoutParams();
layoutParams.width = changeSize.getWidth();
layoutParams.height = changeSize.getHeight();
surfaceView.setLayoutParams(layoutParams);
}
private void changePlayerSize(int pictureWidth, int pictureHeight) {
View root = findViewById(R.id.root);
SurfaceView surfaceView = findViewById(R.id.surface_view);
Size changeSize;
Size viewSize = new Size(root.getWidth(), root.getHeight());
changeSize = calculateViewSize(pictureWidth, pictureHeight, viewSize);
ViewGroup.LayoutParams layoutParams = surfaceView.getLayoutParams();
layoutParams.width = changeSize.getWidth();
layoutParams.height = changeSize.getHeight();
surfaceView.setLayoutParams(layoutParams);
}
private void changeSurfaceLayout() {
int sw;
int sh;
// get screen size
sw = getWindow().getDecorView().getWidth();
sh = getWindow().getDecorView().getHeight();
if (libvlc != null && !libvlc.useCompatSurface())
libvlc.setWindowSize(sw, sh);
double dw = sw, dh = sh;
boolean isPortrait;
isPortrait = false;
if (sw > sh && isPortrait || sw < sh && !isPortrait) {
dw = sh;
dh = sw;
}
// sanity check
if (dw * dh == 0 || mVideoWidth * mVideoHeight == 0) {
Log.e(TAG, "Invalid surface size");
return;
}
// compute the aspect ratio
double ar, vw;
if (mSarDen == mSarNum) {
/* No indication about the density, assuming 1:1 */
vw = mVideoVisibleWidth;
ar = (double)mVideoVisibleWidth / (double)mVideoVisibleHeight;
} else {
/* Use the specified aspect ratio */
vw = mVideoVisibleWidth * (double)mSarNum / mSarDen;
ar = vw / mVideoVisibleHeight;
}
// compute the display aspect ratio
double dar = dw / dh;
switch (mCurrentSize) {
case SURFACE_BEST_FIT:
if (dar < ar)
dh = dw / ar;
else
dw = dh * ar;
break;
case SURFACE_FIT_HORIZONTAL:
dh = dw / ar;
break;
case SURFACE_FIT_VERTICAL:
dw = dh * ar;
break;
case SURFACE_FILL:
break;
case SURFACE_16_9:
ar = 16.0 / 9.0;
if (dar < ar)
dh = dw / ar;
else
dw = dh * ar;
break;
case SURFACE_4_3:
ar = 4.0 / 3.0;
if (dar < ar)
dh = dw / ar;
else
dw = dh * ar;
break;
case SURFACE_ORIGINAL:
dh = mVideoVisibleHeight;
dw = vw;
break;
}
SurfaceView surface;
FrameLayout surfaceFrame;
surface = mSurfaceView;
// surfaceFrame = mSurfaceFrame;
// set display size
LayoutParams lp = surface.getLayoutParams();
lp.width = (int) Math.ceil(dw * mVideoWidth / mVideoVisibleWidth);
lp.height = (int) Math.ceil(dh * mVideoHeight / mVideoVisibleHeight);
surface.setLayoutParams(lp);
// set frame size (crop if necessary)
// lp = surfaceFrame.getLayoutParams();
// lp.width = (int) Math.floor(dw);
// lp.height = (int) Math.floor(dh);
// surfaceFrame.setLayoutParams(lp);
surface.invalidate();
}