下面列出了android.view.TextureView#setLayoutParams ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void init() {
this.mVideoWidth = 0;
this.mVideoHeight = 0;
setBackgroundColor(ViewCompat.MEASURED_STATE_MASK);
setFocusable(true);
setFocusableInTouchMode(true);
requestFocus();
this.mCurrentState = 0;
this.mTargetState = 0;
TextureView renderUIView = new TextureView(getContext());
renderUIView.setLayoutParams(new LayoutParams(-2, -2, 17));
renderUIView.setSurfaceTextureListener(this.mSurfaceCallback);
this.mX8Camera9GridView = new X8Camera9GridView(getContext());
this.mX8Camera9GridView.setLayoutParams(new LayoutParams(-1, -1, 17));
this.mX8AiTrackContainterView = new X8AiTrackContainterView(getContext());
this.mX8AiTrackContainterView.setLayoutParams(new LayoutParams(-1, -1, 17));
this.blackView = new View(getContext());
this.blackView.setLayoutParams(new LayoutParams(-1, -1, 17));
this.blackView.setBackgroundColor(getContext().getResources().getColor(R.color.black));
addView(renderUIView);
addView(this.mX8AiTrackContainterView);
addView(this.blackView);
addView(this.mX8Camera9GridView);
showGridLine(GlobalConfig.getInstance().getGridLine());
}
/**
* get real width and height video
*/
private void getRealSize(MediaPlayer mp, TextureView mTextureView) {
if (mp == null || mTextureView == null) {
return;
}
//Get the dimensions of the video
int videoWidth = mp.getVideoWidth();
int videoHeight = mp.getVideoHeight();
Display display = G.fragmentActivity.getWindowManager().getDefaultDisplay();
int finalWith, finalHeight;
finalWith = display.getWidth();
finalHeight = (int) (((float) videoHeight / (float) videoWidth) * (float) display.getWidth());
if (finalHeight > display.getHeight()) {
finalWith = (int) (((float) finalWith / (float) finalHeight) * (float) display.getHeight());
finalHeight = display.getHeight();
}
ViewGroup.LayoutParams lp = mTextureView.getLayoutParams();
lp.width = finalWith;
lp.height = finalHeight;
mTextureView.setLayoutParams(lp);
}
public TextureView createTextureView() {
//重新为播放器关联TextureView
TextureView textureView = newTextureView();
FrameLayout.LayoutParams params =
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
Gravity.CENTER);
textureView.setLayoutParams(params);
return textureView;
}
@Override
public View createSurface(Context context) {
mTextureView = new TextureView(context);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mTextureView.setLayoutParams(params);
mTextureView.setKeepScreenOn(true);
return mTextureView;
}
public VideoOverlay(Context context) {
super(context);
this.setClickable(false);
this.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// Create surface to display the camera preview
mPreview = new TextureView(context);
mPreview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mPreview.setClickable(false);
mPreview.setSurfaceTextureListener(this);
attachView();
}