使Android應用程序只能在移動設備上以縱向模式運行,而在平板電腦上則允許肖像和橫向導向? 在此先感謝僅支持在移動設備上使用Android支持肖像
1
A
回答
0
在清單中,爲所有的活動設置此:
<activity android:name=".YourActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"/>
讓我解釋一下:
- 隨着
android:configChanges="orientation"
你告訴的Android,你會負責的變化方向。 android:screenOrientation="portrait"
您設置了默認的方向模式。
如果設備是手機,則可以在您的Activity的onCreate方法中調用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
。要確定設備是手機還是平板電腦,您可以查看this question。
1
首先在您的活動或slpash屏幕中檢查應用程序必須在哪個設備上運行。
檢查下面的代碼到您的mainActivity或閃屏。
Intent intent;
if (isTablet(DeciderActivity.this))
{
// for Tablet
intent = new Intent(this, TabletSplashActivity.class);
startActivity(intent);
}
else
{
// for Phone
intent = new Intent(this, PhoneSplashActivity.class);
startActivity(intent);
}
請聲明isTablet方法
public static boolean isTablet() {
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
float yInches = metrics.heightPixels/metrics.ydpi;
float xInches = metrics.widthPixels/metrics.xdpi;
double diagonalInches = Math.sqrt(xInches * xInches + yInches * yInches);
if (diagonalInches >= 7) {
// 7inch device or bigger
return true;
} else {
// smaller device
return false;
}
}
我希望這會爲你工作,這是工作的罰款與我的代碼。
相關問題
- 1. 在移動設備上支持Touch.radiusX
- 2. 移動設備上的WebSocket支持
- 3. JavaScript支持移動設備上的
- 4. 僅支持設備的SDK
- 5. 如何僅在iPhone應用程序上支持肖像模式
- 6. JavaScript WebSockets不支持移動設備?
- 7. 所有移動設備支持SSL?
- 8. 多級移動設備支持
- 9. 谷歌地圖支持移動設備
- 10. 移動偵測並支持舊設備
- 11. 移動設備表支持HTML5?
- 12. Android設備MMS支持
- 13. Android設備/屏幕支持
- 14. Android設備支持的LED
- 15. 的Android支持的設備
- 16. Android ADK支持的設備
- 17. 僅在支持肖像內提交通用應用程序
- 18. UIImagePickerController僅支持肖像模式。任何支持橫向模式的替代品?
- 19. 支持的Android設備:0個設備
- 20. 僅從YouTube API中檢索移動設備支持的視頻
- 21. 僅支持智能手機設備
- 22. Android Manifest僅適用於Android TV - 支持的設備太少?
- 23. 在移動設備上對SVG的支持有多完整?
- 24. CSS3多個背景圖片 - 在移動設備上支持?
- 25. 統一網絡是否支持熱點(在移動設備上)?
- 26. Android支持MediaRouter殺死支持設計
- 27. Android應用支持零設備?
- 28. 在android中支持外部設備
- 29. Backgroud移動支持
- 30. Laravel移動支持
檢查此問題http://stackoverflow.com/questions/5832368/tablet-or-phone-android和這個http://stackoverflow.com/questions/8180764/how-do-i-lock-screen-orientation-對於手機的但不換平板電腦的Android –