0

I am trying to make a VideoView stretch on the whole screen. I have the following layout xml in my project:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    tools:context="com.example.myproject.MainActivity" 
    android:background="@color/green">

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

However, the phone screen looks like this (the background color is green and the width does stretch properly):

Also android:

layout_height="fill_parent" and

layout_height="match_parent"

produces the same result. The phone runs Android 4.4. Also, the theme used is Theme.Holo.Light.NoActionBar, but changing the theme produces the same result (even though the xml preview includes the respective bars). I also remove the title and action bar in the main activity. Here is my MainActivity.java OnCreate() method (this is the only thing I have changed):

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main);
    
    final VideoView videoPlayer = (VideoView)findViewById(R.id.videoView);
    videoPlayer.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.zp);
    videoPlayer.setOnTouchListener(new OnTouchListener() {
        
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            videoPlayer.start();
            return false;
        }
    });
    
}

Can anybody please tell me how can I make the VideoView stretch on the whole screen?

Community
  • 1
  • 1
user2565010
  • 1,876
  • 4
  • 23
  • 37
  • How are you inflating this layout? – laalto Sep 02 '14 at 11:10
  • What about changing `android:layout_height="wrap_content"` to `android:layout_height="match_parent"` as well? :) – MysticMagicϡ Sep 02 '14 at 11:10
  • I have tried changing layout_height to "wrap_content", "match_parent" and "fill_parent" with the same result. – user2565010 Sep 02 '14 at 11:12
  • Try like: `android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:layout_alignParentTop="true"` for VideoView. – MysticMagicϡ Sep 02 '14 at 11:17
  • If by inflation you mean when do I call setContentView(), it is just after the app sets the fullscreen flags. – user2565010 Sep 02 '14 at 11:18
  • I tried aligning the view with its parent (by pasting your lines there). Nothing changed. – user2565010 Sep 02 '14 at 11:20
  • Strange. Try answers on [this](http://stackoverflow.com/questions/3776254/android-video-view-in-fullscreen) and [this](http://stackoverflow.com/questions/11310764/videoview-full-screen-in-android-application) posts then. – MysticMagicϡ Sep 02 '14 at 11:25
  • I tried both solutions. Using the theme Theme.NoTitleBar.Fullscreen in the android manifest does produce a preview showing the view occupying the entirety of the screen (with a small warning sign in the bottom-right corner). However the result is exactly the same. Also manually setting the layout parameters to the ones of the screen's (which are confirmed to be 1080p in height) produces the exact same result. Nothing changed. – user2565010 Sep 02 '14 at 11:36

1 Answers1

1

I hope this will help you,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<VideoView
    android:id="@+id/videoView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>
RajeshVijayakumar
  • 10,281
  • 11
  • 57
  • 84
  • this should work, although fill_parent and match_parent do the same thing, fill_parent was renamed to match_parent in sdk 8 and so we should only be using match_parent. – speedynomads Sep 02 '14 at 11:39
  • It works, it's worth mentioning that the key modification was changing the LinearLayout into RelativeLayout. Also make sure that you add the lines Dhruti posted to make it work. – user2565010 Sep 02 '14 at 11:42
  • LinearLayout places the videoview at the top so you can find the green space below the videoview, but relativelayout will do what you want to do. – RajeshVijayakumar Sep 02 '14 at 11:44