Jibran Khan
Jibran Khan

Reputation: 3256

Android Full Width Video View

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.

Upvotes: 4

Views: 14302

Answers (4)

Madhuri
Madhuri

Reputation: 368

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>

Upvotes: 0

Nirav Ranpara
Nirav Ranpara

Reputation: 13785

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

Upvotes: 2

Cyph3rCod3r
Cyph3rCod3r

Reputation: 2086

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

Upvotes: 5

Torsten Ojaperv
Torsten Ojaperv

Reputation: 1104

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.

Upvotes: 7

Related Questions