Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个应用程序,其中包含一个Activity和一些Fragments。我希望我的应用程序处于纵向模式,但有一个DialogFragment必须检测方向,并相应地更改其布局。
Activity
Fragments
DialogFragment
我怎样才能做到这一点?
在其中onCreate,您应该以编程方式将其方向设置为SCREEN_ORIENTATION_UNSPECIFIED
onCreate
SCREEN_ORIENTATION_UNSPECIFIED
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);