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

熱點內容
單片機投票器 瀏覽:467
程序員那麼可愛唱嗎 瀏覽:830
手機誤刪的app怎麼恢復 瀏覽:700
java第三方加密庫 瀏覽:660
編譯代碼軟體哪個好 瀏覽:997
編譯器軟體圖片 瀏覽:880
美團專送app怎麼不接受遠單 瀏覽:833
伺服器mgmt口如何連接電腦 瀏覽:798
做程序員至少要精通幾種 瀏覽:673
個人用雲伺服器價格對比 瀏覽:257
如何遠程刪除伺服器文件夾 瀏覽:779
a9賬號如何移植到安卓 瀏覽:340
gpib介面編程 瀏覽:468
索尼recovery編譯 瀏覽:878
app後端php 瀏覽:625
中獎的app叫什麼名字 瀏覽:92
定時關機命令批處理 瀏覽:941
閃電pdf 瀏覽:642
winform原生編譯 瀏覽:337
同比提升比的演算法 瀏覽:887