0

我有一个视频视图。当我触摸它时,它应该显示在一个几乎全屏视图的对话框中。为此,我使用了以下代码:

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 恶意代码:

    <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>

现在的问题是,视频正在对话框中播放。但是视频出现在对话框的右侧。对话框左侧有很多空白区域。控制器隐藏在对话框后面。所以我无法使用视频控制器控制视频,因为我无法触摸它。

谁能帮我..

4

3 回答 3

1

我想在mVideoDialog.setContentView(R.layout.fullscreen_video);你打电话之前mVideoDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN) 让对话框全屏显示。

于 2012-09-18T07:19:42.343 回答
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>
于 2012-09-18T07:26:42.200 回答
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();

于 2016-09-05T04:46:20.230 回答