I have an application in which activity and fragment, I have declared in the manifest for activity but for fragment I want landscape mode it working but after Java code all layout also changes in landscape mode I want on few fragment layout should be landscape and rest will be in portrait mode.
public class CustomizeFragment extends Fragment implements View.OnKeyListener, View.OnClickListener, StringConstants, BundleConstants, NetConstants, AlertDFragment.AlertListener {
private int mAlertIdentifier;
private String TAG = CustomizeFragment.class.getSimpleName();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_customize, container, false);
// getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
getActivity().setRequestedOrientation(SCREEN_ORIENTATION_LANDSCAPE);
init(rootView);
}
}
Before opening any fragment in landscape mode, you can change the orientation of the application by calling the below method in onclicklistener or so.
getActivity().setRequestedOrientation(SCREEN_ORIENTATION_LANDSCAPE);
so that when application changes the fragment, it is adjusted.
添加在横向显示的所有片段“layout-land”文件夹以及在potrait模式下显示的所有片段“layout-port”
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.