1.VideoView播放视频的时候遇到了不能设置控件的宽高或者全屏的问题,这个时候就需要写一个类继承VideoView

import android.content.Context;import android.util.AttributeSet;import android.widget.VideoView;public class VideoViewFullScreen extends VideoView {public VideoViewFullScreen(Context context) {super(context);}public VideoViewFullScreen(Context context, AttributeSet attrs) {super(context, attrs);}public VideoViewFullScreen(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int width = getDefaultSize(0, widthMeasureSpec);int height = getDefaultSize(0, heightMeasureSpec);setMeasuredDimension(width, height);}}

然后用布局文件引用这个自定义的类

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <com.example.work.VideoViewFullScreen        android:id="@+id/video_view"        android:layout_width="match_parent"        android:layout_height="match_parent" /></LinearLayout>
2.接下来就是VideoView播放raw下的视频文件

package com.example.work;import android.app.Activity;import android.net.Uri;import android.os.Bundle;import android.view.Window;import android.view.WindowManager;import android.widget.MediaController;import android.widget.VideoView;public class VideoViewActivity extends Activity {private VideoView video_view;private MediaController mediaController;@Overrideprotected void onCreate(Bundle savedInstanceState) {    //去掉通知栏    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);     //去掉 标题    this.requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState);setContentView(R.layout.videoview);video_view=(VideoView)findViewById(R.id.video_view);mediaController=new MediaController(this);video_view.setMediaController(mediaController);//下面android.resource://是固定的,com.example.work是包名,R.raw.sw是你raw文件夹下的视频文件 video_view.setVideoURI(Uri.parse("android.resource://com.example.work/"+R.raw.sw));video_view.start();}}


更多相关文章

  1. Android(安卓)自定义ScrollView 实现拉下伸缩头部view
  2. Android(安卓)Tips
  3. Android(安卓)Toast带图标水平布局的简单实现
  4. android水平ProgressBar颜色设置
  5. Android(安卓)databinding RecycleView item 子控件点击事件
  6. Android:ListView优化
  7. android常用控件(二)
  8. android按屏幕大小动态确定控件位置及大小
  9. UI 开源代码 FileBrowserView

随机推荐

  1. android > Android实现计时与倒计时的几
  2. android6.0创建文件问题
  3. Android 进化
  4. Android Jetpack Navigation 的使用
  5. 怎样使用android自带例子程序
  6. Android AudioRecord录音实现
  7. 【Android】记一次Ninja引发的血案
  8. ReactNative异常:{"errno":-4048,"code":"
  9. 使用Android Studio开发百度地图LBS过程
  10. SQlite与android 的数据交互 (android 项