導航:首頁 > 操作系統 > 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掃碼豎屏相關的資料

熱點內容
編程教育老師成長心態 瀏覽:257
音頻採集單片機 瀏覽:590
加密管的優點 瀏覽:280
dock基礎命令 瀏覽:345
java編程愛好者 瀏覽:723
做外包程序員怎麼樣 瀏覽:865
程序員技術門檻 瀏覽:473
路由花生殼搭建web伺服器地址 瀏覽:541
小米傳送文件用什麼app 瀏覽:102
哪個領域演算法好 瀏覽:380
用命令行編譯java 瀏覽:677
筆趣閣app哪個是正版手機app 瀏覽:427
程序員這個工作好嗎 瀏覽:898
agps定位伺服器地址 瀏覽:659
用水做的解壓玩具怎麼做 瀏覽:418
安卓411能下載什麼 瀏覽:304
小海龜logo命令 瀏覽:493
java製作界面 瀏覽:895
台達plc編程電纜製作 瀏覽:249
30多歲當程序員 瀏覽:442