【发布时间】:2015-12-10 16:55:36
【问题描述】:
当我将设备横向旋转为纵向或纵向旋转为横向时,设备不会刷新 UI。我正在使用片段“onCreateView”和“onConfigurationChanged”来绘制布局,remote_gesture 和 remote_navigation 有纵向和横向两种布局。最后将android:configChanges="orientation|screenSize|keyboardHidden"添加到AndroidManifest.xml
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
//View rootView = (View)inflater.inflate(R.layout.remote_navigation, container, false);
View rootView = (View)inflater.inflate(R.layout.fragment_remote, container, false);
viewSwitcher =(ViewSwitcher)rootView.findViewById(R.id.remote_viewswitcher);
remoteGesture = (View)inflater.inflate(R.layout.remote_gesture, null);
remoteNav = (View)inflater.inflate(R.layout.remote_navigation, null);
viewSwitcher.addView(remoteNav);
viewSwitcher.addView(remoteGesture);
setupButtons(rootView);
return rootView;
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.w(TAG, "rrr... onConfigurationChanged...");
ViewGroup container = (ViewGroup) getView();
//container.removeAllViewsInLayout();
LayoutInflater inflater = (LayoutInflater) getActivity().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootView = (View)inflater.inflate(R.layout.fragment_remote, container, false);
viewSwitcher = (ViewSwitcher) rootView.findViewById(R.id.remote_viewswitcher);
remoteGesture = (View) inflater.inflate(R.layout.remote_gesture, null);
remoteNav = (View)inflater.inflate(R.layout.remote_navigation, null);
viewSwitcher.addView(remoteNav);
viewSwitcher.addView(remoteGesture);
}
我该如何解决这个问题?
【问题讨论】: