今天使用videoview 播放MP4文件时,无法全屏播放,于是找了好多的方法都没有办法全屏。下面是我自己写的继承videoview 的类,
- package com.nwsuaf.fairgroundsnavigation.ui;
-
-
- 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)
- {
- int width = getDefaultSize(0, widthMeasureSpec);
- int height = getDefaultSize(0, heightMeasureSpec);
- setMeasuredDimension(width , height);
- }
-
-
- }
然后再xml使用这个自定义的fullscreenvideoview就可以啦,
布局文件也贴出来吧!
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas./apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <com.nwsuaf.fairgroundsnavigation.ui.FullScreenVideoView
- android:id="@+id/videoView"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_gravity="center"
- />
- </LinearLayout>
希望对大家有用!
|