0

Am using Video view to play the MP4 video files from external card. when i rotate my android device video not showing full screen. am working on android 4.4 normal including the ui output screen below enter image description here when i rotate phone enter image description here

<LinearLayout 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:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/video"
        android:orientation="vertical"
        android:background="@drawable/planebackground">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/videotoolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.AppBarLayout>

        <RelativeLayout
            android:id="@+id/layout1"

            android:layout_width="wrap_content"
            android:layout_height="200dp"
            >

            <VideoView
                android:id="@+id/VideoView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/layout1"
            android:weightSum="1">

            <TextView
                android:text="About Course"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:textSize="16sp"
                android:layout_marginLeft="19dp"
                android:layout_marginStart="19dp"
                android:layout_marginTop="70dp"
                android:id="@+id/aboutcuz" />

            <TextView
                android:text="TextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="48dp"
                android:id="@+id/about_course_text"
                android:fontFamily="Arial"
                android:layout_below="@+id/aboutcuz"
                android:layout_alignLeft="@+id/aboutcuz"
                android:layout_alignStart="@+id/aboutcuz"
                android:layout_marginLeft="43dp"
                android:layout_marginStart="43dp"
                android:gravity="center"
                />

            <TextView
                android:text="TextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:lines="2"
                android:scrollHorizontally="true"
                android:ellipsize="end"
                android:id="@+id/coursenamev"
                android:textSize="18sp"
                android:layout_alignParentTop="true"
                android:layout_alignLeft="@+id/aboutcuz"
                android:layout_alignStart="@+id/aboutcuz"
                android:layout_marginTop="18dp" />
            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="60dp"

                android:background="@android:color/darker_gray"/>
            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@+id/aboutcuz"
                android:layout_marginTop="10dp"

                android:background="@android:color/darker_gray"/>


        </RelativeLayout>


    </LinearLayout>

is there any layout issue in my code

luee
  • 65
  • 2
  • 9

4 Answers4

1

Please try this. I hope this may result you desired results.

<LinearLayout 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:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:id="@+id/video"
          android:orientation="vertical">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/videotoolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:id="@+id/layout1"

    android:layout_width="match_parent"
    android:layout_height="200dp"
    >

    <VideoView
        android:id="@+id/VideoView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/layout1"
    android:weightSum="1">

    <TextView
        android:text="About Course"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textSize="16sp"
        android:layout_marginLeft="19dp"
        android:layout_marginStart="19dp"
        android:layout_marginTop="70dp"
        android:id="@+id/aboutcuz" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="48dp"
        android:id="@+id/about_course_text"
        android:fontFamily="Arial"
        android:layout_below="@+id/aboutcuz"
        android:layout_alignLeft="@+id/aboutcuz"
        android:layout_alignStart="@+id/aboutcuz"
        android:layout_marginLeft="43dp"
        android:layout_marginStart="43dp"
        android:gravity="center"
        />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:lines="2"
        android:scrollHorizontally="true"
        android:ellipsize="end"
        android:id="@+id/coursenamev"
        android:textSize="18sp"
        android:layout_alignParentTop="true"
        android:layout_alignLeft="@+id/aboutcuz"
        android:layout_alignStart="@+id/aboutcuz"
        android:layout_marginTop="18dp" />
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="60dp"

        android:background="@android:color/darker_gray"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/aboutcuz"
        android:layout_marginTop="10dp"

        android:background="@android:color/darker_gray"/>


</RelativeLayout>

Dushyant Suthar
  • 673
  • 2
  • 9
  • 27
0

Make your custom VideoView class

public class FullScreenVideoView extends VideoView {
    public FullScreenVideoView(Context context) {
        super(context);
    }

    public FullScreenVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FullScreenVideoView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
    }

    public void setFixedVideoSize(int width, int height)
    {
        getHolder().setFixedSize(width, height);
    }
}

and set in your Layout insted of VideoView

<yourpackage.FullScreenVideoView
                android:id="@+id/VideoView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />
Yash ajabiya
  • 134
  • 2
  • 8
0

Do something like this

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Logger.debug(TAG, "onConfigChanged");
        updateLayout(newConfig.orientation);
    }

 /**
     * Update the current layout params according to current device orientation.
     */
    private void updateLayout(int orientation) {
        LinearLayout.LayoutParams favParams = (LinearLayout.LayoutParams) mFavoriteLayout.getLayoutParams();
        LinearLayout.LayoutParams historyParams = (LinearLayout.LayoutParams) mHistoryLayout.getLayoutParams();
        LinearLayout.LayoutParams colParams = (LinearLayout.LayoutParams) mColumnLayout.getLayoutParams();
        if (orientation == Configuration.ORIENTATION_PORTRAIT) {
            mColumnLayout.setOrientation(LinearLayout.VERTICAL);
            historyParams.width = favParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
            historyParams.height = favParams.height = 0;
            colParams.weight = 1.0f;
        } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            mColumnLayout.setOrientation(LinearLayout.HORIZONTAL);
            historyParams.height = favParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
            historyParams.width = favParams.width = 0;
            colParams.weight = 2.0f;
        }

        // Set back updated params and redraw
        mFavoriteLayout.setLayoutParams(favParams);
        mHistoryLayout.setLayoutParams(historyParams);
        mColumnLayout.setLayoutParams(colParams);
        mColumnLayout.invalidate();
    }

When you change orientation change weight and you can achieve what you want.

Ankit Khare
  • 1,345
  • 11
  • 30
-1

It's quite simple.You can find an example when you create a new "full screen activity".

It's something like this:

// Hide UI first
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.hide();
    }
    mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);