admin管理员组文章数量:1021430
I want to lock screen orientation to portrait for tablet. and I implemented this in onCreate() method. However, the scree orientation doesn't keep portrait and it's causing unnecessary flicker and re-creation of the activity. I don't know why. Please help me. The dialog shows when dialogUiState is not null.
if (DeviceUtils.isTablet(this) && dialogUiState != null) {
requestedOrientation = (ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT)
}
object DeviceUtils {
@JvmStatic
fun isTablet(context: Context): Boolean {
val configuration = context.resources.configuration
val screenLayoutSize = configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
return screenLayoutSize > Configuration.SCREENLAYOUT_SIZE_NORMAL
}
}
I want to know how to lock the screen orientaion to portrait for tablet.
I want to lock screen orientation to portrait for tablet. and I implemented this in onCreate() method. However, the scree orientation doesn't keep portrait and it's causing unnecessary flicker and re-creation of the activity. I don't know why. Please help me. The dialog shows when dialogUiState is not null.
if (DeviceUtils.isTablet(this) && dialogUiState != null) {
requestedOrientation = (ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT)
}
object DeviceUtils {
@JvmStatic
fun isTablet(context: Context): Boolean {
val configuration = context.resources.configuration
val screenLayoutSize = configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
return screenLayoutSize > Configuration.SCREENLAYOUT_SIZE_NORMAL
}
}
I want to know how to lock the screen orientaion to portrait for tablet.
Share Improve this question edited Nov 29, 2024 at 2:04 John asked Nov 28, 2024 at 9:45 JohnJohn 631 silver badge9 bronze badges 2 |1 Answer
Reset to default 2You should use SCREEN_ORIENTATION_PORTRAIT
to ignore sensor.
According to the docs, SCREEN_ORIENTATION_SENSOR_PORTRAIT
can still use the sensor:
Would like to have the screen in portrait orientation, but can use the sensor to change which direction the screen is facing.
I want to lock screen orientation to portrait for tablet. and I implemented this in onCreate() method. However, the scree orientation doesn't keep portrait and it's causing unnecessary flicker and re-creation of the activity. I don't know why. Please help me. The dialog shows when dialogUiState is not null.
if (DeviceUtils.isTablet(this) && dialogUiState != null) {
requestedOrientation = (ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT)
}
object DeviceUtils {
@JvmStatic
fun isTablet(context: Context): Boolean {
val configuration = context.resources.configuration
val screenLayoutSize = configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
return screenLayoutSize > Configuration.SCREENLAYOUT_SIZE_NORMAL
}
}
I want to know how to lock the screen orientaion to portrait for tablet.
I want to lock screen orientation to portrait for tablet. and I implemented this in onCreate() method. However, the scree orientation doesn't keep portrait and it's causing unnecessary flicker and re-creation of the activity. I don't know why. Please help me. The dialog shows when dialogUiState is not null.
if (DeviceUtils.isTablet(this) && dialogUiState != null) {
requestedOrientation = (ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT)
}
object DeviceUtils {
@JvmStatic
fun isTablet(context: Context): Boolean {
val configuration = context.resources.configuration
val screenLayoutSize = configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
return screenLayoutSize > Configuration.SCREENLAYOUT_SIZE_NORMAL
}
}
I want to know how to lock the screen orientaion to portrait for tablet.
Share Improve this question edited Nov 29, 2024 at 2:04 John asked Nov 28, 2024 at 9:45 JohnJohn 631 silver badge9 bronze badges 2- Please elaborate on how it "doesn't work". What is your goal and what's going wrong? – Jan Itor Commented Nov 28, 2024 at 11:37
-
I can actually rotate the screen which I don't want. I want to lock the screen orientation to portrait. What should I set to
android:configChanges =
andandroid:screenOrientation=
? My goal is that the screen orientation keeps portrait even though I rotate the screen. – John Commented Nov 28, 2024 at 16:18
1 Answer
Reset to default 2You should use SCREEN_ORIENTATION_PORTRAIT
to ignore sensor.
According to the docs, SCREEN_ORIENTATION_SENSOR_PORTRAIT
can still use the sensor:
Would like to have the screen in portrait orientation, but can use the sensor to change which direction the screen is facing.
本文标签: kotlinHow can I lock screen orientation to portrait for tablet (Android)Stack Overflow
版权声明:本文标题:kotlin - How can I lock screen orientation to portrait for tablet? (Android) - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745518773a2154217.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
android:configChanges =
andandroid:screenOrientation=
? My goal is that the screen orientation keeps portrait even though I rotate the screen. – John Commented Nov 28, 2024 at 16:18