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


Java Display.getWidth方法代码示例

本文整理汇总了Java中android.view.Display.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Display.getWidth方法的具体用法?Java Display.getWidth怎么用?Java Display.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.Display的用法示例。


在下文中一共展示了Display.getWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initFromCameraParameters

import android.view.Display; //导入方法依赖的package包/类
/**
 * Reads, one time, values from the camera that are needed by the app.
 */
void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    previewFormat = parameters.getPreviewFormat();
    previewFormatString = parameters.get("preview-format");

    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    screenResolution = new Point(display.getWidth(), display.getHeight());

    Point screenResolutionForCamera = new Point();
    screenResolutionForCamera.x = screenResolution.x;
    screenResolutionForCamera.y = screenResolution.y;
    // preview size is always something like 480*320, other 320*480
    if (screenResolution.x < screenResolution.y) {
        screenResolutionForCamera.x = screenResolution.y;
        screenResolutionForCamera.y = screenResolution.x;
    }
    cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);

}
 
开发者ID:RuanXiaoHui,项目名称:ZxingScan,代码行数:24,代码来源:CameraConfigurationManager.java

示例2: getScreenSize

import android.view.Display; //导入方法依赖的package包/类
/**
 * 获取屏幕尺寸
 */
@SuppressLint("ObsoleteSdkInt")
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static Point getScreenSize() {
    WindowManager windowManager = (WindowManager) sContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = null;
    if (windowManager != null) {
        display = windowManager.getDefaultDisplay();
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        if (display != null) {
            return new Point(display.getWidth(), display.getHeight());
        } else {
            return null;
        }
    } else {
        Point point = new Point();
        if (display != null) {
            display.getSize(point);
        }
        return point;
    }
}
 
开发者ID:ChunweiDu,项目名称:Utils,代码行数:27,代码来源:DensityUtil.java

示例3: initFromCameraParameters

import android.view.Display; //导入方法依赖的package包/类
public void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    WindowManager manager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    mScreenResolution = new Point(display.getWidth(), display.getHeight());
    Point screenResolutionForCamera = new Point();
    screenResolutionForCamera.x = mScreenResolution.x;
    screenResolutionForCamera.y = mScreenResolution.y;

    // preview size is always something like 480*320, other 320*480
    if (mScreenResolution.x < mScreenResolution.y) {
        screenResolutionForCamera.x = mScreenResolution.y;
        screenResolutionForCamera.y = mScreenResolution.x;
    }

    cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
}
 
开发者ID:devzwy,项目名称:NeiHanDuanZiTV,代码行数:18,代码来源:CameraConfigurationManager.java

示例4: setBehindWidth

import android.view.Display; //导入方法依赖的package包/类
/**
 * Sets the behind width.
 *
 * @param i The width the Sliding Menu will open to, in pixels
 */
@SuppressWarnings("deprecation")
public void setBehindWidth(int i) {
	int width;
	Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
			.getDefaultDisplay();
	try {
		Class<?> cls = Display.class;
		Class<?>[] parameterTypes = {Point.class};
		Point parameter = new Point();
		Method method = cls.getMethod("getSize", parameterTypes);
		method.invoke(display, parameter);
		width = parameter.x;
	} catch (Exception e) {
		width = display.getWidth();
	}
	setBehindOffset(width-i);
}
 
开发者ID:6ag,项目名称:LiuAGeAndroid,代码行数:23,代码来源:SlidingMenu.java

示例5: showLoadingDialog

import android.view.Display; //导入方法依赖的package包/类
@DoMain
public void showLoadingDialog(String msg) {
    String content = null;
    if (msg == null) {
        content = "正在与服务器交互,请稍后.....";
    } else {
        content = msg;
    }
    View view = View.inflate(activity, R.layout.view_loading_dialog, null);
    ((TextView) view.findViewById(R.id.view_loading_dialog_desc)).setText(content);
    alertDialog = new AlertDialog.Builder(activity)
            .setView(view)
            .create();
    alertDialog.show();
    WindowManager m = activity.getWindowManager();
    Display d = m.getDefaultDisplay();
    Window dialogWindow = alertDialog.getWindow();
    WindowManager.LayoutParams p = dialogWindow.getAttributes();
    p.width = (int) (d.getWidth() * 0.8);
    dialogWindow.setAttributes(p);
}
 
开发者ID:penghongru,项目名称:Coder,代码行数:22,代码来源:BaseFragment.java

示例6: onCreate

import android.view.Display; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setGravity(Gravity.BOTTOM);
    getWindow().setWindowAnimations(R.style.dialog_anim);
    WindowManager m = getWindow().getWindowManager();
    Display d = m.getDefaultDisplay();
    WindowManager.LayoutParams p = getWindow().getAttributes();
    p.height = (int) (d.getHeight() * 0.7);
    p.width = d.getWidth();
    p.y = Util.dip2px(50);
    getWindow().setAttributes(p);

}
 
开发者ID:liuke2016,项目名称:filepicker,代码行数:15,代码来源:FolderDialog.java

示例7: getScreenOrientation

import android.view.Display; //导入方法依赖的package包/类
public static int getScreenOrientation(Context context) {
    Display display = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
    if (display.getWidth() == display.getHeight()) {
        return 3;
    }
    if (display.getWidth() < display.getHeight()) {
        return 1;
    }
    return 2;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:11,代码来源:DisplayUtils.java

示例8: showThankDialog

import android.view.Display; //导入方法依赖的package包/类
public static void showThankDialog(final Activity act,Handler handler, final boolean isFinish) {
	ThankDialog.Builder customBuilder = new ThankDialog.Builder(act);
	customBuilder.setMessage(act.getResources().getString(ResourceUtils.getIdByName(act,
			"string", "sobot_thank_dialog_hint")));
	final ThankDialog d = customBuilder.create();
	d.show();

	int width = ScreenUtils.getScreenWidth(act);
	WindowManager windowManager = act.getWindowManager();
	Display display = windowManager.getDefaultDisplay();
	if(d.getWindow() != null){
		WindowManager.LayoutParams lp = d.getWindow().getAttributes();
		if (width == 480) {
			lp.width = display.getWidth() - 120; // 设置宽度
		} else {
			lp.width = display.getWidth() - 200; // 设置宽度
		}
	}

	handler.postDelayed(new Runnable() {
		@Override
		public void run() {
			if(!act.isFinishing()){
				d.dismiss();
				if(isFinish){
					act.finish();
				}
			}
		}
	},2000);
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:32,代码来源:ChatUtils.java

示例9: initFromCameraParameters

import android.view.Display; //导入方法依赖的package包/类
/**
	 * Reads, one time, values from the camera that are needed by the app.
	 */
	void initFromCameraParameters(Camera camera) {
		Camera.Parameters parameters = camera.getParameters();
		previewFormat = parameters.getPreviewFormat();
		previewFormatString = parameters.get("preview-format");
		Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
		WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		Display display = manager.getDefaultDisplay();
		screenResolution = new Point(display.getWidth(), display.getHeight());
		Log.d(TAG, "Screen resolution: " + screenResolution);

//		//Lemon add 扫描框修改,解决拉伸但导致成像模糊识别率很低。<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
//		Point screenResolutionForCamera = new Point();
//		screenResolutionForCamera.x = screenResolution.x;
//		screenResolutionForCamera.y = screenResolution.y;
//		// preview size is always something like 480*320, other 320*480
//		if (screenResolution.x < screenResolution.y) {
//			screenResolutionForCamera.x = screenResolution.y;
//			screenResolutionForCamera.y = screenResolution.x;
//		}
		//Lemon add 扫描框修改,解决拉伸>>>>>>>>>>>>>>>>>>>>>>>>>>>>

		//Lemon 扫描框修改,解决拉伸但导致成像模糊识别率很低  screenResolution改为screenResolutionForCamera);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		cameraResolution = getCameraResolution(parameters, screenResolution);
		Log.d(TAG, "Camera resolution: " + screenResolution);
		//Lemon 扫描框修改,解决拉伸但导致成像模糊识别率很低   screenResolution改为screenResolutionForCamera);>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	}
 
开发者ID:TommyLemon,项目名称:APIJSON-Android-RxJava,代码行数:30,代码来源:CameraConfigurationManager.java

示例10: setButtomAndWidth

import android.view.Display; //导入方法依赖的package包/类
/**
 * 设置宽度全屏,并从下面弹出,添加动画
 */
public void setButtomAndWidth() {

    getWindow().setGravity(Gravity.BOTTOM); //显示在底部
    WindowManager m = getWindow().getWindowManager();
    Display d = m.getDefaultDisplay();
    WindowManager.LayoutParams p = getWindow().getAttributes();
    p.width = d.getWidth(); //设置dialog的宽度为当前手机屏幕的宽度
    getWindow().setAttributes(p);
    getWindow().setWindowAnimations(R.style.popWindow);

}
 
开发者ID:ALguojian,项目名称:DialogHelper,代码行数:15,代码来源:BaseDialog.java

示例11: initFromCameraParameters

import android.view.Display; //导入方法依赖的package包/类
/**
 * Reads, one time, values from the camera that are needed by the app.
 */
void initFromCameraParameters(Camera camera) {
  Camera.Parameters parameters = camera.getParameters();
  previewFormat = parameters.getPreviewFormat();
  previewFormatString = parameters.get("preview-format");
  Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
  WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  Display display = manager.getDefaultDisplay();
  screenResolution = new Point(display.getWidth(), display.getHeight());
  Log.d(TAG, "Screen resolution: " + screenResolution);
  cameraResolution = getCameraResolution(parameters, screenResolution);
  Log.d(TAG, "Camera resolution: " + screenResolution);
}
 
开发者ID:CoderCF,项目名称:ZXingDemo,代码行数:16,代码来源:CameraConfigurationManager.java

示例12: getScaleBitmap

import android.view.Display; //导入方法依赖的package包/类
public static Bitmap getScaleBitmap(Activity context, String filePath) {
    BitmapFactory.Options opt = new BitmapFactory.Options();
    // 这个isjustdecodebounds很重要
    opt.inJustDecodeBounds = true;
    Bitmap bm;
    BitmapFactory.decodeFile(filePath, opt);

    // 获取到这个图片的原始宽度和高度
    int picWidth = opt.outWidth;
    int picHeight = opt.outHeight;

    // 获取屏的宽度和高度
    WindowManager windowManager = context.getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    int screenWidth = display.getWidth();
    int screenHeight = display.getHeight();

    // isSampleSize是表示对图片的缩放程度,比如值为2图片的宽度和高度都变为以前的1/2
    opt.inSampleSize = 1;
    // 根据屏的大小和图片大小计算出缩放比例
    if (picWidth > picHeight) {
        if (picWidth > screenWidth)
            opt.inSampleSize = picWidth / screenWidth;
    } else {
        if (picHeight > screenHeight)

            opt.inSampleSize = picHeight / screenHeight;
    }
    // 这次再真正地生成一个有像素的,经过缩放了的bitmap
    opt.inJustDecodeBounds = false;
    bm = BitmapFactory.decodeFile(filePath, opt);

    return bm;

}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:36,代码来源:CompressImage.java

示例13: calculateMaxBitmapSize

import android.view.Display; //导入方法依赖的package包/类
/**
 * This method calculates maximum size of both width and height of bitmap.
 * It is twice the device screen diagonal for default implementation (extra quality to zoom image).
 * Size cannot exceed max texture size.
 *
 * @return - max bitmap size in pixels.
 */
@SuppressWarnings({"SuspiciousNameCombination", "deprecation"})
public static int calculateMaxBitmapSize(@NonNull Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point size = new Point();
    int width, height;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        width = size.x;
        height = size.y;
    } else {
        width = display.getWidth();
        height = display.getHeight();
    }

    // Twice the device screen diagonal as default
    int maxBitmapSize = (int) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));

    // Check for max texture size via Canvas
    Canvas canvas = new Canvas();
    final int maxCanvasSize = Math.min(canvas.getMaximumBitmapWidth(), canvas.getMaximumBitmapHeight());
    if (maxCanvasSize > 0) {
        maxBitmapSize = Math.min(maxBitmapSize, maxCanvasSize);
    }

    // Check for max texture size via GL
    final int maxTextureSize = EglUtils.getMaxTextureSize();
    if (maxTextureSize > 0) {
        maxBitmapSize = Math.min(maxBitmapSize, maxTextureSize);
    }

    Log.d(TAG, "maxBitmapSize: " + maxBitmapSize);
    return maxBitmapSize;
}
 
开发者ID:Alcatraz323,项目名称:MaterialOCR,代码行数:43,代码来源:BitmapLoadUtils.java

示例14: getScreenWidth

import android.view.Display; //导入方法依赖的package包/类
/**
 * 获取屏幕的宽度
 *
 * @param context
 * @return
 */
public static int getScreenWidth(Context context) {
    WindowManager manager = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    return display.getWidth();
}
 
开发者ID:Horrarndoo,项目名称:YiZhi,代码行数:13,代码来源:ScreenUtils.java

示例15: SuperSwipeRefreshLayout

import android.view.Display; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public SuperSwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    /**
     * getScaledTouchSlop是一个距离,表示滑动的时候,手的移动要大于这个距离才开始移动控件。如果小于这个距离就不触发移动控件
     */
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(
            android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(
            DECELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context
            .obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    WindowManager wm = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mHeaderViewWidth = (int) display.getWidth();
    mFooterViewWidth = (int) display.getWidth();
    mHeaderViewHeight = (int) (HEADER_VIEW_HEIGHT * metrics.density);
    mFooterViewHeight = (int) (FOOTER_VIEW_HEIGHT * metrics.density);
    defaultProgressView = new CircleProgressView(getContext());
    createHeaderViewContainer();
    createFooterViewContainer();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    density = metrics.density;
    mTotalDragDistance = mSpinnerFinalOffset;
}
 
开发者ID:FreeSunny,项目名称:Amazing,代码行数:38,代码来源:SuperSwipeRefreshLayout.java


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