iro*_*xxx 14 android android-fragments
在我的应用程序中,除了一个特定的模式外,我在纵向模式下FragmentActivity有多个.我之间移动通过尾小号S IN的.FragmentFragmentFragmentViewFragmentActivity
当有方向改变时,我有一个不同的布局(实际上具有相同的名称但不同的小部件View)Fragment.在横向模式下,我想从Fragment布局View和页脚View中删除特定的小部件FragmentActivity,当回到纵向时,将所有内容添加回来.
我已经保存了所需的所有数据,但我最好onSavedInstanceState()在Fragment哪里测试方向更改,以便我可以View适当地恢复?
不知道我可以覆盖onConfigurationChange(),并在我的测试有Fragment,因为我不具备的机器人:configChanges ="方向"在我的Android Manifest.
Vik*_*pta 31
将此签入保留在onCreate()上.当您旋转设备时,应用程序将重新启动.因此,当应用重启时,会再次调用onCreate.
int currentOrientation = getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
// Landscape
}
else {
// Portrait
}
Run Code Online (Sandbox Code Playgroud)
ACe*_*giz 16
您也可以通过覆盖onConfigurationChanged片段的功能来控制方向更改.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
int currentOrientation = getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE){
Log.v("TAG","Landscape !!!");
}
else {
Log.v("TAG","Portrait !!!");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11085 次 |
| 最近记录: |