VideoView在Android应用程序全屏全屏、应用程序、VideoView、Android

2023-09-05 10:55:19 作者:深情不及久伴

我在我的应用程序中的videoview。在code是这样的。

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>

视频查看宽度和hieght中提到的XML文件。我要的是,有一次,我preSS一个按钮videoview应该在全屏幕上,一旦我preSS后退按钮的videoview应该回到它提到的大小。请大家帮忙?

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?

推荐答案

设置全屏这样一来,

             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);