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

熱點內容
pdf列印底色去掉 瀏覽:443
java快遞介面 瀏覽:385
哪個app可以教新爸爸 瀏覽:208
如何查看伺服器系統版本信息 瀏覽:524
成都市土地出讓金演算法 瀏覽:702
鋼筋加密標記 瀏覽:575
ps中擴展功能在文件夾的什麼位置 瀏覽:903
雙極壓縮機為什麼要先高壓 瀏覽:527
蘋果手機伺服器填什麼 瀏覽:832
android移動動畫效果 瀏覽:691
電子和伺服器是什麼意思 瀏覽:691
phpurl中文亂碼問題 瀏覽:893
程序員那麼可愛大結局陸漓產子 瀏覽:538
java如何從雲伺服器讀取本地文件 瀏覽:923
壓縮空氣軟管製作方法 瀏覽:912
天河三號演算法 瀏覽:924
php隊列教程 瀏覽:632
洪水命令 瀏覽:530
安卓怎麼弄成蘋果在線 瀏覽:435
谷歌web伺服器地址 瀏覽:900