我有一个视频在一个视频播放和循环作为我的登录/注册活动的背景。视频播放和循环很好,除非它不覆盖整个屏幕。活动锁定在纵向模式,但视频只显示在屏幕的下半部分(好像在景观模式)。videoview本身确实覆盖了整个屏幕。这是我目前的密码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
VideoView videoView = (VideoView) findViewById(R.id.launcherVideo);
Uri src = Uri.parse("android.resource://com.package/raw/video");
videoView.setVideoURI(src);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setVolume(0, 0);
mp.setLooping(true);
}
});
//videoView.setMediaController(new MediaController(this));
videoView.start();
}这是我的xml
<VideoView
android:id="@+id/launcherVideo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/linearLayout" />如何使视频全屏在任何大小的设备上?
发布于 2016-09-30 04:25:57
您可以尝试使用TextureView而不是VideoView,这是回答描述的。
发布于 2016-09-30 04:59:52
由于没有看到整个布局xml,我想这可能会有所帮助。
尝试用一个VideoView包装您的RelativeLayout,并将它对齐到父程序:
<VideoView
android:id="@+id/launcherVideo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true">发布于 2018-09-14 11:43:01
<RelativeLayout
android:id="@+id/video_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/progress_limit">
<com.example.FullScreenVideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="false"
android:layout_centerInParent="true"
/>
</RelativeLayout>也可以使用它对我有用的代码
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);
}
}https://stackoverflow.com/questions/39782591
复制相似问题