How to set multiple fragments in landscape mode, and rest should be portrait in android?

I have an application where an activity and a fragment, I declared in the manifest for the activity, but for the fragment, I want the landscape mode to work, but after the Java code, all layouts also change in landscape mode. I want a small fragment of the layout to have a landscape and the 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);
}
}

      

+3


source to share


2 answers


Before opening any fragment in landscape mode, you can change the orientation of the application by calling the method below in the onclicklistener or so.

getActivity().setRequestedOrientation(SCREEN_ORIENTATION_LANDSCAPE);

      



so that when the application changes, the snippet is adjusted.

+1


source


add the entire "layout-land" slice of the slice to be displayed in landscape orientation and the entire "layout-port" slice displayed in the cut mode



0


source







All Articles