AndroidView应用程序中的VideoView全屏

Coo*_*ler 24 android

我的申请中有视频.代码是这样的.

<?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>
Run Code Online (Sandbox Code Playgroud)

xml文件中提到了视频宽度和高度.我想要的是,一旦我按下按钮,视频视图应该全屏显示,一旦我按下后退按钮,视频视图应该回到它提到的大小.请帮忙?

Sri*_*nth 38

我必须让我的VideoView坐在RelativeLayout中才能使所选答案有效.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <VideoView android:id="@+id/videoViewRelative"
         android:layout_alignParentTop="true"
         android:layout_alignParentBottom="true"
         android:layout_alignParentLeft="true"
         android:layout_alignParentRight="true"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">
    </VideoView>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

如下所示:Android - 如何拉伸视频以填充VideoView区域在屏幕大小之间切换就像更改所选答案中给出的布局参数一样简单.

  • 是.是真的.只有RelativeLayout才能使其全屏显示.谢谢你的亮点. (2认同)
  • 非常感谢,顺便说一句,因为它是2018年,所以改用`“ match_parent”`,因为如今已不赞成使用“ fill_parent”`。 (2认同)

Aqi*_*mid 37

以这种方式设置全屏,

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);
Run Code Online (Sandbox Code Playgroud)

然后回到orignal尺寸.

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);
Run Code Online (Sandbox Code Playgroud)

  • 这不适合我...我的视频视图是一个片段,设置布局参数后没有任何反应(参数是正确的) (7认同)
  • 它不适合我。我认为它没有拉伸视频视图。 (2认同)

Hir*_*tel 21

我这样做了:

检查这些参考屏幕截图.

在此输入图像描述

添加类FullScreenVideoView.java:

import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;

public class FullScreenVideoView extends VideoView {
    public FullScreenVideoView(Context context) {
        super(context);
    }

    public FullScreenVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FullScreenVideoView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
    }
}
Run Code Online (Sandbox Code Playgroud)

如何与xml 绑定:

<FrameLayout
   android:id="@+id/secondMedia"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

     <com.my.package.customview.FullScreenVideoView
           android:layout_width="match_parent"
           android:layout_height="match_parent" 
           android:id="@+id/fullScreenVideoView"/>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

希望这会帮助你.


Xar*_*mer 12

第一种方法

当您要为该活动全屏打开视频时,您必须在Manifest中设置主题属性.设置这个值

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
Run Code Online (Sandbox Code Playgroud)

这里以编程方式更改主题

第二种方法

创建另一个fullscreen.xml,如下图所示,setContentView(R.layout.fullscreen)然后单击按钮

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <VideoView android:id="@+id/myvideoview"
        android:layout_width="fill_parent"
        android:layout_alignParentRight="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_height="fill_parent">
    </VideoView>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)


Vin*_*kla 11

在按钮上单击开始native video player将打开full screen:

Intent intent = new Intent(Intent.ACTION_VIEW );
intent.setDataAndType(Uri.parse(path), "video/*");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)