我有一个视频观看。当我触摸它时,它应该显示在几乎全屏视图的对话框中。为此,我使用了以下代码:
mVideoFirst.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
mVideoFirst.stopPlayback();
mVideoDialog.show();
mVideoFullScreen.setVideoPath(clip1.getAbsolutePath());
mMediaController3.setMediaPlayer(mVideoFullScreen);
mVideoFullScreen.setMediaController(mMediaController3);
mVideoFullScreen.requestFocus();
mVideoFullScreen.start();
return false;
}
});
对于我使用以下java代码的对话框:
mVideoDialog = new Dialog(this);
mVideoDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mVideoDialog.setContentView(R.layout.fullscreen_video);
mVideoDialog.setOnKeyListener(this);
mVideoFullScreen = (VideoView) mVideoDialog.findViewById(R.id.fullscreen_videoview);
这是我对话框的xml vile:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView
android:id="@+id/fullscreen_videoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</VideoView>
</RelativeLayout>
现在的问题是,视频正在对话框中播放。但视频出现在对话框的右侧。对话框左侧有很多空白区域。控制器隐藏在对话框后面。所以我无法使用视频控制器控制视频,因为我无法触摸它。
任何人都可以帮助我..
答案 0 :(得分:0)
我想在mVideoDialog.setContentView(R.layout.fullscreen_video);
之前,您应该致电mVideoDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
以使对话框全屏显示。
答案 1 :(得分:0)
您需要将布局和视频视图的高度和宽度设置为匹配父级。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView
android:id="@+id/fullscreen_videoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</VideoView>
答案 2 :(得分:0)
您可以像这样制作自定义视频视图控件:
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);
}
}
并在xml中使用此控件:
<com.yourpackagename.FullScreenVideoView
android:id="@+id/videoView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
对话框屏幕:
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
View dialogView = inflater.inflate(R.layout.your_custom_dialog_xml, null);
dialogBuilder.setView(dialogView);
final Dialog dialog = dialogBuilder.create();
dialog.setCancelable(false);
dialog.show();