本文整理汇总了Java中android.view.SurfaceView.setLayoutParams方法的典型用法代码示例。如果您正苦于以下问题:Java SurfaceView.setLayoutParams方法的具体用法?Java SurfaceView.setLayoutParams怎么用?Java SurfaceView.setLayoutParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.SurfaceView
的用法示例。
在下文中一共展示了SurfaceView.setLayoutParams方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import android.view.SurfaceView; //导入方法依赖的package包/类
private void initialize(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr,
@StyleRes int defStyleRes) {
mPreviewView = new SurfaceView(context);
mPreviewView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mViewFinderView = new ViewFinderView(context);
mViewFinderView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
mButtonSize = Math.round(displayMetrics.density * BUTTON_SIZE_DP);
mAutoFocusButton = new ImageView(context);
mAutoFocusButton.setLayoutParams(new LayoutParams(mButtonSize, mButtonSize));
mAutoFocusButton.setScaleType(ImageView.ScaleType.CENTER);
mAutoFocusButton.setImageResource(R.drawable.ic_code_scanner_auto_focus_on);
mAutoFocusButton.setOnClickListener(new AutoFocusClickListener());
mFlashButton = new ImageView(context);
mFlashButton.setLayoutParams(new LayoutParams(mButtonSize, mButtonSize));
mFlashButton.setScaleType(ImageView.ScaleType.CENTER);
mFlashButton.setImageResource(R.drawable.ic_code_scanner_flash_on);
mFlashButton.setOnClickListener(new FlashClickListener());
if (attrs == null) {
mViewFinderView.setSquareFrame(DEFAULT_SQUARE_FRAME);
mViewFinderView.setMaskColor(DEFAULT_MASK_COLOR);
mViewFinderView.setFrameColor(DEFAULT_FRAME_COLOR);
mViewFinderView.setFrameThickness(Math.round(DEFAULT_FRAME_THICKNESS_DP * displayMetrics.density));
mViewFinderView.setFrameCornersSize(Math.round(DEFAULT_FRAME_CORNER_SIZE_DP * displayMetrics.density));
mAutoFocusButton.setColorFilter(DEFAULT_AUTO_FOCUS_BUTTON_COLOR);
mFlashButton.setColorFilter(DEFAULT_FLASH_BUTTON_COLOR);
mAutoFocusButton.setVisibility(DEFAULT_AUTO_FOCUS_BUTTON_VISIBILITY);
mFlashButton.setVisibility(DEFAULT_FLASH_BUTTON_VISIBILITY);
} else {
TypedArray attributes = null;
try {
attributes = context.getTheme()
.obtainStyledAttributes(attrs, R.styleable.CodeScannerView, defStyleAttr, defStyleRes);
mViewFinderView.setSquareFrame(
attributes.getBoolean(R.styleable.CodeScannerView_squareFrame, DEFAULT_SQUARE_FRAME));
mViewFinderView
.setMaskColor(attributes.getColor(R.styleable.CodeScannerView_maskColor, DEFAULT_MASK_COLOR));
mViewFinderView.setFrameColor(
attributes.getColor(R.styleable.CodeScannerView_frameColor, DEFAULT_FRAME_COLOR));
mViewFinderView.setFrameThickness(attributes
.getDimensionPixelSize(R.styleable.CodeScannerView_frameThickness,
Math.round(DEFAULT_FRAME_THICKNESS_DP * displayMetrics.density)));
mViewFinderView.setFrameCornersSize(attributes
.getDimensionPixelSize(R.styleable.CodeScannerView_frameCornersSize,
Math.round(DEFAULT_FRAME_CORNER_SIZE_DP * displayMetrics.density)));
mAutoFocusButton.setColorFilter(attributes
.getColor(R.styleable.CodeScannerView_autoFocusButtonColor, DEFAULT_AUTO_FOCUS_BUTTON_COLOR));
mFlashButton.setColorFilter(
attributes.getColor(R.styleable.CodeScannerView_flashButtonColor, DEFAULT_FLASH_BUTTON_COLOR));
mAutoFocusButton.setVisibility(attributes.getBoolean(R.styleable.CodeScannerView_autoFocusButtonVisible,
DEFAULT_AUTO_FOCUS_BUTTON_VISIBLE) ? VISIBLE : INVISIBLE);
mFlashButton.setVisibility(attributes
.getBoolean(R.styleable.CodeScannerView_flashButtonVisible, DEFAULT_FLASH_BUTTON_VISIBLE) ?
VISIBLE : INVISIBLE);
} finally {
if (attributes != null) {
attributes.recycle();
}
}
}
addView(mPreviewView);
addView(mViewFinderView);
addView(mAutoFocusButton);
addView(mFlashButton);
}