当前位置: 首页>>代码示例>>Java>>正文


Java SurfaceView.setLayoutParams方法代码示例

本文整理汇总了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);
}
 
开发者ID:yuriy-budiyev,项目名称:code-scanner,代码行数:66,代码来源:CodeScannerView.java


注:本文中的android.view.SurfaceView.setLayoutParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。