當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。