Android 横向模式下的全屏视频视图

Android 横向模式下的全屏视频视图,android,android-fullscreen,android-videoview,Android,Android Fullscreen,Android Videoview,我希望在横向模式下使VideoView全屏显示。我试过了。它显示从左到右的边距。我想知道怎样才能使VideoView全屏显示 我的.xml文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layo

我希望在横向模式下使VideoView全屏显示。我试过了。它显示从左到右的边距。我想知道怎样才能使VideoView全屏显示

我的.xml文件

<?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"
    android:orientation="vertical" >

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

您可以向清单文件中的活动添加主题:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
对于xml格式的VideoView,请更改

android:layout_height="wrap_content"


这将帮助您在视频视图中实现全屏显示。希望能有所帮助。

在使用onCreate函数设置ContentView之前添加以下代码。我希望有帮助

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

全屏横向视频

AndroidManifext.xml(设置方向)

FullScreenMediaController.java代码:

import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

public class Video1 extends AppCompatActivity {

private VideoView videoView;
private MediaController mediaController;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video1);

    videoView = findViewById(R.id.videoView);
    String fullScreen =  getIntent().getStringExtra("fullScreenInd");
    if("y".equals(fullScreen)){
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getSupportActionBar().hide();
    }

    Uri videoUri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.YOUR_VIDEO_NAME);

    videoView.setVideoURI(videoUri);

    mediaController = new FullScreenMediaController(this);
    mediaController.setAnchorView(videoView);

    videoView.setMediaController(mediaController);
    videoView.start();
    }
}
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.MediaController;

public class FullScreenMediaController extends MediaController {

private ImageButton fullScreen;
private String isFullScreen;

public FullScreenMediaController(Context context) {
    super(context);
}

@Override
public void setAnchorView(View view) {

    super.setAnchorView(view);

    //image button for full screen to be added to media controller
    fullScreen = new ImageButton (super.getContext());

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.RIGHT;
    params.rightMargin = 80;
    addView(fullScreen, params);

    //fullscreen indicator from intent
    isFullScreen =  ((Activity)getContext()).getIntent().
            getStringExtra("fullScreenInd");

    if("y".equals(isFullScreen)){
        fullScreen.setImageResource(R.drawable.ic_fullscreen_exit);
    }else{
        fullScreen.setImageResource(R.drawable.ic_fullscreen);
    }

    //add listener to image button to handle full screen and exit full screen events
    fullScreen.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(getContext(),Video1.class);

            if("y".equals(isFullScreen)){
                intent.putExtra("fullScreenInd", "");
            }else{
                intent.putExtra("fullScreenInd", "y");
            }
            ((Activity)getContext()).startActivity(intent);
        }
    });
  }
}

@RahulMatte您是否也在清单中添加了
android:configChanges=“orientation | screenSize”
?我正在强制活动仅在横向模式下打开……所以我想我不需要OK。尝试添加
requestWindowFeature(Window.FEATURE\u NO\u TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,WindowManager.LayoutParams.FLAG_全屏)
这两行在
setContentView
之前@rahulmateok..在setContentView getWindow().clearFlags(WindowManager.LayoutParams.FLAG\u FORCE\u NOT\u FULLSCREEN)之后,我已经有了这一行了;getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,WindowManager.LayoutParams.FLAG_全屏)@RahulMatte你能在setContentView之前检查一下这是否有效吗?好的…我知道videoview根据源文件的分辨率显示分辨率…好的。但是我可以把它扩展到全屏吗?我试过你的代码,它不起作用。最好保存纵横比,不管怎样,使用下面的属性可能会对你有所帮助。android:layout\u height=“fill\u parent”android:layout\u weighht=“fill\u parent”
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Video1">

<VideoView
    android:id="@+id/videoView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent">
</VideoView>
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

public class Video1 extends AppCompatActivity {

private VideoView videoView;
private MediaController mediaController;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video1);

    videoView = findViewById(R.id.videoView);
    String fullScreen =  getIntent().getStringExtra("fullScreenInd");
    if("y".equals(fullScreen)){
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getSupportActionBar().hide();
    }

    Uri videoUri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.YOUR_VIDEO_NAME);

    videoView.setVideoURI(videoUri);

    mediaController = new FullScreenMediaController(this);
    mediaController.setAnchorView(videoView);

    videoView.setMediaController(mediaController);
    videoView.start();
    }
}
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.MediaController;

public class FullScreenMediaController extends MediaController {

private ImageButton fullScreen;
private String isFullScreen;

public FullScreenMediaController(Context context) {
    super(context);
}

@Override
public void setAnchorView(View view) {

    super.setAnchorView(view);

    //image button for full screen to be added to media controller
    fullScreen = new ImageButton (super.getContext());

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.RIGHT;
    params.rightMargin = 80;
    addView(fullScreen, params);

    //fullscreen indicator from intent
    isFullScreen =  ((Activity)getContext()).getIntent().
            getStringExtra("fullScreenInd");

    if("y".equals(isFullScreen)){
        fullScreen.setImageResource(R.drawable.ic_fullscreen_exit);
    }else{
        fullScreen.setImageResource(R.drawable.ic_fullscreen);
    }

    //add listener to image button to handle full screen and exit full screen events
    fullScreen.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(getContext(),Video1.class);

            if("y".equals(isFullScreen)){
                intent.putExtra("fullScreenInd", "");
            }else{
                intent.putExtra("fullScreenInd", "y");
            }
            ((Activity)getContext()).startActivity(intent);
        }
    });
  }
}