1

My all app is in portrait, but I need one activity to be adaptive in all the 4 position, portrait, landscape, etc...

How can I do it programmatically and/or in the configuration to get an auto rotate to check a video.

Here is my configuration:

<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativeLayout"
    android:configChanges="orientation|screenSize"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/activity_video_share_scene"
    tools:context=".VideoShare">

    <Button
        android:id="@+id/btnShare"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="1dp"
        android:text="Share"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <VideoView
        android:id="@+id/videoView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:configChanges="orientation|screenSize"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.motion.widget.MotionLayout>

Here is my code:

public class VideoShare extends AppCompatActivity {

    VideoView videoView;
    MediaController mController;

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        int orientation = getResources().getConfiguration().orientation;
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            // In landscape
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            // In portrait
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);

Any ideas? Thanks in advance.

ΩlostA
  • 2,501
  • 5
  • 27
  • 63
  • 1
    Check this one [answer](https://stackoverflow.com/a/4909079/8393260), I think that's what you are looking for – Olena Y Nov 13 '20 at 15:38
  • @OlenaY Perfect, I had to remove all the orientation configuration and code, and just add this line of this answer you have me. You can put your answer I will complete what I did precisely : https://stackoverflow.com/a/18892471/3581620 – ΩlostA Nov 13 '20 at 16:01
  • 1
    I added the answer. Happy that link helped you :) – Olena Y Nov 19 '20 at 15:27
  • @OlenaY Where is the answer, it disappeared? – ΩlostA Nov 19 '20 at 18:08
  • yeah, This post is hidden. It was deleted 19 hours ago by Martijn Pieters♦ – Olena Y Nov 20 '20 at 11:14

0 Answers0