分享

android使用videoview 全屏方法

 lifei_szdz 2013-09-23
今天使用videoview 播放MP4文件时,无法全屏播放,于是找了好多的方法都没有办法全屏。下面是我自己写的继承videoview 的类,


  1. package com.nwsuaf.fairgroundsnavigation.ui;  
  2.   
  3.   
  4. import android.content.Context;  
  5. import android.util.AttributeSet;  
  6. import android.widget.VideoView;  
  7.   
  8.   
  9. public class FullScreenVideoView extends VideoView{  
  10.   
  11.   
  12. public FullScreenVideoView(Context context) {  
  13. super(context);  
  14. // TODO Auto-generated constructor stub  
  15. }  
  16. public FullScreenVideoView (Context context, AttributeSet attrs)  
  17. {  
  18. super(context,attrs);  
  19. }  
  20. public FullScreenVideoView(Context context, AttributeSet attrs,int defStyle)  
  21. {  
  22. super(context,attrs,defStyle);  
  23. }  
  24. @Override  
  25. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)  
  26. {  
  27.   int width = getDefaultSize(0, widthMeasureSpec);  
  28.   int height = getDefaultSize(0, heightMeasureSpec);  
  29.   setMeasuredDimension(width , height);  
  30. }  
  31.   
  32.   
  33. }  




然后再xml使用这个自定义的fullscreenvideoview就可以啦,
布局文件也贴出来吧!


  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas./apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7.     <com.nwsuaf.fairgroundsnavigation.ui.FullScreenVideoView  
  8.      android:id="@+id/videoView"  
  9.      android:layout_width="fill_parent"  
  10.      android:layout_height="fill_parent"  
  11.      android:layout_gravity="center"  
  12.     />  
  13. </LinearLayout>  




希望对大家有用!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多