Is it possible simple to detect current orientation of android device, without programming a listener and handling the position matrix? In my app I want only to know current orientation - vertical or horizontal - at the moment. However I don't want to listen to events of axiometry or other events.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You just need to know the height and the width of your canvas... your surface... your monitor... etc.
maybe you can get it with :
There is a nice article about this subject which is a have-to-read: One Screen Turn Deserves Another
This may not be relevant, but if by chance you need to know this because you want to lock the device into its’ current orientation you can toggle between the following two lines of code.
You can also use:
I think the safest and easiest way is to add a tag for some element of your activity in XML. For example, set the viewpager's tag to "portrait" in the portrait layout and set it to "landscape" in in landscape. Then in your oncreate check for that tag like so:
Use the
getRotation
method:From the documentation:
Keep in mind that
getRotation
was introduced from Android 2.2. UsegetOrientation
if your target are older devices.