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

熱點內容
北漂程序員出車禍 瀏覽:914
亞馬遜為什麼用雲端伺服器 瀏覽:65
程序員審核職位 瀏覽:385
德龍空調壓縮機 瀏覽:780
紅旗app如何注冊新賬戶 瀏覽:360
慣導pdf 瀏覽:606
c程序員的平均工資 瀏覽:58
微小店源碼 瀏覽:801
編譯原理答題題庫 瀏覽:169
ubuntu編程入門 瀏覽:301
antbuild命令 瀏覽:771
怎麼訂閱伺服器 瀏覽:593
視頻專用加密器哪個好用 瀏覽:295
app無法使用網路哪裡設置 瀏覽:847
紅旗linux怎麼安裝 瀏覽:136
各種破車窗工具測試解壓 瀏覽:933
優格手錶app如何使用 瀏覽:716
docker進入容器命令 瀏覽:498
先河私有雲伺服器價格 瀏覽:459
java字體代碼 瀏覽:829