Cool Compiler Cool Compiler - 5 months ago 86
Android Question

VideoView Full screen in android application

i have a videoview in my application. the code is like this.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical"
android:background="@drawable/opsbuds">
<TextView android:text="TextView" android:id="@+id/adtxt1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<VideoView android:layout_width="300dip"
android:layout_height="250dip" android:id="@+id/videoView11" android:layout_marginLeft="30dip"></VideoView>

<LinearLayout android:layout_width="match_parent"
android:id="@+id/llv11" android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>

<Button android:text=" Continue " android:id="@+id/button1211"
android:layout_width="wrap_content" android:textStyle="bold"
android:layout_marginTop="10dp" android:layout_height="wrap_content"
android:textSize="20dp" android:layout_marginLeft="5dp"
android:textColor="#800080" android:background="@drawable/button"></Button>
</LinearLayout>




the video view width and hieght is mentioned in xml file. What i want is , once i press a button the videoview should come on full screen and once i press back button the videoview should go back to its mentioned size. please help?

Answer

set fullscreen this way,

             DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
             android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams();
             params.width =  metrics.widthPixels;
             params.height = metrics.heightPixels;
             params.leftMargin = 0;
             videoView.setLayoutParams(params);

and back to orignal size, this way.

             DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
             android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams();
             params.width =  (int) (300*metrics.density);
             params.height = (int) (250*metrics.density);
             params.leftMargin = 30;
             videoView.setLayoutParams(params);
Comments