导航:首页 > 操作系统 > android扫码竖屏

android扫码竖屏

发布时间:2022-09-07 15:17:31

android使用Zxing扫描二维码改成竖屏后,后面的预览画面出现了拉伸,扭曲的情况,有没有哪位大牛解决了,急求

更改CameraConfigurationManager.java文件

在 Log.d(TAG, "Screen resolution: " + screenResolution);这句之后增加
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, screenResolution);为cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);

代码下载地址:http://download.csdn.net/detail/moonql70/5032148

Ⅱ android开发横竖屏问题

Android横屏竖屏设置

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置成全屏模式

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE););//强制为横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
我做的东西里面还用到了去掉标题栏。
我也贴出来
requestWindowFeature(Window.FEATURE_NO_TITLE);

垂直居中:

android:layout_centerVertical="true"

水平居中:

android:layout_centerHorizontal="true"

1.hideStatusbarAndTitlebar()隐藏statusbar和titlebar.

private void hideStatusbarAndTitlebar() {
final Window win = getWindow();
// No Statusbar
win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// No Titlebar
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
2.设置屏幕显示模式ScreenOrientation.

在activity里设置android:screenOrientation的值。
android:screenOrientation的属性有以下值:
unspecified(默 认值,由系统判断状态自动切换),The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.
landscape,横屏
portrait,竖屏
user(用户当前设置的orientation值),The user's current preferred orientation.
behind(下一个要显示的Activity的orientation值),The same orientation as the activity that's immediately beneath it in the activity stack.
sensor(传 感器的方向),The orientation determined by a physical orientation sensor. The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device.
nosensor(不 使用传感器,这个效果差不多等于unspecified).An orientation determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device. Except for this distinction, the system chooses the orientation using the same policy as for the "unspecified" setting.

3.水平/垂直居中的方法.

设置parent的android:gravity为"center"。

4.获得当前屏幕宽高的方法.

Display display = getWindowManager().getDefaultDisplay();
Config.screenWidth = display.getWidth();
Config.screenHeight = display.getHeight();

Ⅲ Android开发中如何强制横屏和强制竖屏设置

在Androidmanifest.xml里面设置,

android:screenOrientation="portrait" 竖屏
android:screenOrientation="landscape" 横屏

Ⅳ android如何在代码中判断横竖屏

Android中判断横竖屏是通过Configuration 这个类来判断的。

  1. Configuration.ORIENTATION_LANDSCAPE 表示横屏。

  2. Configuration.ORIENTATION_PORTRAIT表示竖屏。


以下是完整代码:

public boolean isScreenChange() {

Configuration mConfiguration = context.getResources().getConfiguration(); //获取设置的配置信息
int ori = mConfiguration.orientation ; //获取屏幕方向
if(ori == Configuration.ORIENTATION_LANDSCAPE){
//横屏
return true;
}else if(ori == Configuration.ORIENTATION_PORTRAIT){
//竖屏
return false;
}
return false;
}


避免在转屏时重启Activity

android中每次屏幕方向切换时都会重启Activity,所以应该在Activity销毁前保存当前活动的状态,在Activity再次 Create的时候载入配置,那样,进行中的游戏就不会自动重启了!
要避免在转屏时重启Activity,可以通过在AndroidManifest.xml文件中重新定义方向(给每个Activity加上android:configChanges=”keyboardHidden|orientation”属性)。
在需要控制屏幕显示方向的Activity中重写onConfigurationChanged(Configuration newConfig)方法,这样在转屏时就不会重启Activity了。

阅读全文

与android扫码竖屏相关的资料

热点内容
文件名修改为文件夹的名字批处理 浏览:251
拍照程序员 浏览:827
wps怎么把pdf转jpg 浏览:217
自拍用什么app做的艺术照 浏览:169
h3c无线配置命令 浏览:515
linux代码阅读工具 浏览:160
能够画出对称图形的是什么app 浏览:424
单片机投票器 浏览:467
程序员那么可爱唱吗 浏览:830
手机误删的app怎么恢复 浏览:700
java第三方加密库 浏览:660
编译代码软件哪个好 浏览:997
编译器软件图片 浏览:880
美团专送app怎么不接受远单 浏览:833
服务器mgmt口如何连接电脑 浏览:798
做程序员至少要精通几种 浏览:673
个人用云服务器价格对比 浏览:257
如何远程删除服务器文件夹 浏览:779
a9账号如何移植到安卓 浏览:340
gpib接口编程 浏览:468