4

I am trying to stretch my video view inside the linear layout to full screen but it doesn't match the device screen. Here is my code

<LinearLayout
     android:id="@+id/linearLayout1"
     android:layout_width="fill_parent"
     android:layout_height="720dp"
     android:layout_alignParentBottom="true"
     android:layout_alignParentLeft="true"
     android:layout_alignParentTop="true"
     android:layout_alignParentRight="true"
     android:layout_gravity="fill_horizontal"
     android:layout_marginTop="140dp" >

<VideoView
    android:id="@+id/videoView1"
    android:layout_width="fill_parent"
    android:layout_height="720dp" />

</LinearLayout>

There is always 10 to 15 dp space on left and right each. Also the Linear layout is not stretching to full screen. I want it to fill the screen in width.

Jibran Khan
  • 3,236
  • 4
  • 37
  • 50

4 Answers4

7

Actually there's no need to set width programmatically

android:layout_width="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"

Should suffice to fill the container with full width video view. And use match_parent instead of fill_parent. Hope this helps somebody.

Torsten Ojaperv
  • 1,014
  • 17
  • 24
5

You can get current height and width of the screen using display matrix

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int h = displaymetrics.heightPixels;
int w = displaymetrics.widthPixels;

Now use this height and width for your video view :) use it programmatically not hardcode it like 720dp and all. getWidth() and getHeight() are deprecated by the google

MashukKhan
  • 1,946
  • 1
  • 27
  • 46
Cyph3rCod3r
  • 1,978
  • 23
  • 33
  • Actually @rawD3buGGG3R's answer worked for me and i will suggest to set the parameters programatically to acheive desired implmenetation. – Jibran Khan Mar 21 '13 at 05:08
  • .getDefaultDisplay() and getDisplay are depricated it cause crash or issue from API 30 what is the alternative for this – Bhushan Shirsath Apr 08 '21 at 07:22
2

Get run time height and width of your layout and set that in VideoView

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();                  
//videoview.setLayoutParams(new FrameLayout.LayoutParams(550,550));                    
videoview.setLayoutParams(new FrameLayout.LayoutParams(width,height));

//FrameLayout : write your  layout name which you used
MashukKhan
  • 1,946
  • 1
  • 27
  • 46
Nirav Ranpara
  • 13,753
  • 3
  • 39
  • 54
0

Try using fill_parent in android:layout_height instead of using specific height.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:layout_gravity="fill_horizontal">

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

</LinearLayout>
MashukKhan
  • 1,946
  • 1
  • 27
  • 46
Madhuri
  • 368
  • 1
  • 10