sajidnehal
sajidnehal

Reputation: 33

How to set few fragment be landscape mode and rest should be portrait in android?

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);
}
}

Upvotes: 3

Views: 1300

Answers (2)

pratz9999
pratz9999

Reputation: 548

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.

Upvotes: 3

Mr. Programmer
Mr. Programmer

Reputation: 14

add all fragment "layout-land" folder which display in landscape and all fragment "layout-port" that display on potrait mode

Upvotes: -1

Related Questions